我正在尝试让我的 handler.ashx 页面在我们的新 AWS Windows 实例上运行,我已经安装了 IIS,并且看起来处理程序在实例上工作所需的一切,但是当我将值传递给处理程序并尝试连接时到我们的 MSSQL DB,我得到了这个异常。
System.ComponentModel.Win32Exception (0x80004005): 找不到网络路径
我不确定可能出了什么问题,我在网上到处检查,大多数帖子都与不正确的连接字符串有关,但是我 100% 肯定我的连接字符串是正确的,因为我在托管的个人服务器上使用了相同的处理程序寄宿生。我也让处理程序在我的本地主机上完美运行。
处理程序代码:
<%@ WebHandler Language="C#" Class="PassHandler" %>
using System;
using System.Web;
using System.Data.SqlClient;
public class PassHandler : IHttpHandler
{
//www.mammothvr.com/PASSHandler/PassHandler.ashx?Key=
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//GET from UE4 PASS
if (context.Request.HttpMethod.ToString() == "GET")
{
//context.Response.Write("You sent a post!");
//get key from UE4
string KeyFromUE4 = context.Request.QueryString["Key"];
if (KeyFromUE4 == null)
{
context.Response.Write("ITS WORKING WITHOUT DB CONNECTION");
return;
}
//variables for later use
bool Validated = false;
int timetrial = 0;
int TrialDays = 0;
string temp = "";
//create reader obj
SqlDataReader rdr = null;
//create a connection object
SqlConnection conn = new SqlConnection(@"DeletedConnectionStringForThisPost");
conn.Close();
//create a command object
SqlCommand cmd = new SqlCommand("select * from PASSDBKEYS.dbo.Keys", conn);
try
{
// open the connection
conn.Open();
temp += " opened the connection";
// 1. get an instance of the SqlDataReader
rdr = cmd.ExecuteReader();
temp += " executed reader";
//while connection is reading rows
while (rdr.Read())
{
// get the results of each column
string Key = (string)rdr["PassKey"];
bool used = (bool)rdr["Used"];
bool Valid = (bool)rdr["Valid"];
bool IsTrial = (bool)rdr["IsTrialKey"];
temp += Key;
//check to see if key is used and if it is valid
if (Key == KeyFromUE4)
{
if (Valid == true)
{
if (IsTrial == true)
{
//check time left on trial
TrialDays = Convert.ToInt32(rdr["TrialDays"]);
DateTime DateActivated = (DateTime)rdr["DateActivated"];
timetrial = DateTime.Now.DayOfYear - DateActivated.DayOfYear;
if (TrialDays < timetrial) //if time is up on trial, set not valid anymore
{
Validated = false;
rdr.Close();
//new SqlCommand(" UPDATE Account SET name = Aleesha, CID = 24 Where name =Areeba and CID =11 )";
SqlCommand CMD = new SqlCommand("Update PASSDBKEYS.dbo.Keys SET Valid = 0 WHERE PassKey = @PassKey;", conn);
CMD.Parameters.Add(new SqlParameter("@PassKey", KeyFromUE4));
CMD.ExecuteNonQuery();
break;
}
}
else //not a trial account
{
Validated = true;
break;
}
}
else //key not valid anymore
{
Validated = false;
}
}
else if (Key != KeyFromUE4) //not a valid key
{
Validated = false;
}
}
}
//catch exception
catch (SqlException ex)
{
temp += ex.InnerException;
//rdr.Close();
conn.Close();
}
finally
{
//close the reader if it is done rading
if (rdr != null)
{
//close the reader
rdr.Close();
conn.Close();
}
else
{
//rdr.Close();
conn.Close();
}
}
//Send message back to UE4
if (Validated == true)
{
context.Response.Write("1");
}
else
{
context.Response.Write("Tried to read" +temp);
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
如果我只是在 AWS 实例上运行处理程序,没有关键参数,那么一切都很好,因为在这种情况下我没有连接到我的数据库,但是当我传递一个参数时,我得到了错误(因为只有那么脚本应该连接到数据库)
任何帮助都会令人惊叹,我在这里慢慢开始失去理智,坚持了几个小时无济于事。