The remote server returned an error: (500) Internal Server Error on website
The remote server returned an error: (500) Internal Server Error on website
我通过 http://datalan.aspone.cz/ 访问 运行 网站时遇到问题,红色 table 中的数据仍然不可用,结果返回以下错误消息
“错误关闭
远程服务器返回错误:(500)
内部服务器错误。"
此外,网站已经 运行 在本地主机上,没有问题。
我不知道我哪里错了,但如果有人能帮助解决这些问题,我将不胜感激。
我附上下面的代码:
public List<Data> Generate()
{
List<Data> data = new List<Data>();
WebRequest request = WebRequest.Create("http://192.168.1.100/st0.xml");
request.Credentials = new System.Net.NetworkCredential("admin", "admin");
WebResponse response;
Stream ReceiveStream;
XmlTextReader reader = null;
try
{
response = request.GetResponse();
ReceiveStream = response.GetResponseStream();
reader = new XmlTextReader(ReceiveStream);
}
catch (WebException ex)
{
response = ex.Response;
ReceiveStream = response.GetResponseStream();
}
List<Tuple<string, string, int>> values = new List<Tuple<string, string, int>>();
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "ia0":
double temp = Convert.ToDouble(reader.ReadString()) / 10;
values.Add(new Tuple<string, string, int>(String.Format(temp.ToString() + " °C"), "Temperature", 0));
break;
case "ia1":
double vol = Convert.ToDouble(reader.ReadString()) / 10;
values.Add(new Tuple<string, string, int>(String.Format(vol.ToString() + "V"), "Voltage", 1));
break;
case "di0":
values.Add(new Tuple<string, string, int>(reader.ReadString(), "INPD0", 2));
break;
case "di1":
values.Add(new Tuple<string, string, int>(reader.ReadString(), "INPD1", 3));
break;
case "di2":
values.Add(new Tuple<string, string, int>(reader.ReadString(), "INPD2", 4));
break;
case "di3":
values.Add(new Tuple<string, string, int>(reader.ReadString(), "INPD3", 5));
break;
case "out0":
values.Add(new Tuple<string, string, int>(reader.ReadString(), "OUT0", 6));
break;
case "out1":
values.Add(new Tuple<string, string, int>(reader.ReadString(), "OUT1", 7));
break;
case "out2":
values.Add(new Tuple<string, string, int>(reader.ReadString(), "OUT2", 8));
break;
case "out3":
values.Add(new Tuple<string, string, int>(reader.ReadString(), "OUT3", 9));
break;
}
}
}
for (int i = 0; i < values.Count; i++)
{
for (int j = 0; j < values.Count; j++)
{
if (i == values[j].Item3)
{
data.AddRange(new List<Data> { new Data { Type = values[j].Item2, Value = values[j].Item1 } });
}
}
}
return data;
}
很可能与这段代码有关:
WebRequest request = WebRequest.Create("http://192.168.1.100/st0.xml");
您正在调用一个本地 IP 地址,如果它是在共享主机上,它可能不会喜欢这个请求。
我已经解决了这些问题。
找到解决方案后,我通过以下步骤编辑了 Web.config 中的代码:
<location path="." inheritInChildApplications="false">
<system.web>
...
...
...
</system.web>
</location>
下次可以帮到别人。
我通过 http://datalan.aspone.cz/ 访问 运行 网站时遇到问题,红色 table 中的数据仍然不可用,结果返回以下错误消息 “错误关闭 远程服务器返回错误:(500) 内部服务器错误。"
此外,网站已经 运行 在本地主机上,没有问题。
我不知道我哪里错了,但如果有人能帮助解决这些问题,我将不胜感激。
我附上下面的代码:
public List<Data> Generate()
{
List<Data> data = new List<Data>();
WebRequest request = WebRequest.Create("http://192.168.1.100/st0.xml");
request.Credentials = new System.Net.NetworkCredential("admin", "admin");
WebResponse response;
Stream ReceiveStream;
XmlTextReader reader = null;
try
{
response = request.GetResponse();
ReceiveStream = response.GetResponseStream();
reader = new XmlTextReader(ReceiveStream);
}
catch (WebException ex)
{
response = ex.Response;
ReceiveStream = response.GetResponseStream();
}
List<Tuple<string, string, int>> values = new List<Tuple<string, string, int>>();
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "ia0":
double temp = Convert.ToDouble(reader.ReadString()) / 10;
values.Add(new Tuple<string, string, int>(String.Format(temp.ToString() + " °C"), "Temperature", 0));
break;
case "ia1":
double vol = Convert.ToDouble(reader.ReadString()) / 10;
values.Add(new Tuple<string, string, int>(String.Format(vol.ToString() + "V"), "Voltage", 1));
break;
case "di0":
values.Add(new Tuple<string, string, int>(reader.ReadString(), "INPD0", 2));
break;
case "di1":
values.Add(new Tuple<string, string, int>(reader.ReadString(), "INPD1", 3));
break;
case "di2":
values.Add(new Tuple<string, string, int>(reader.ReadString(), "INPD2", 4));
break;
case "di3":
values.Add(new Tuple<string, string, int>(reader.ReadString(), "INPD3", 5));
break;
case "out0":
values.Add(new Tuple<string, string, int>(reader.ReadString(), "OUT0", 6));
break;
case "out1":
values.Add(new Tuple<string, string, int>(reader.ReadString(), "OUT1", 7));
break;
case "out2":
values.Add(new Tuple<string, string, int>(reader.ReadString(), "OUT2", 8));
break;
case "out3":
values.Add(new Tuple<string, string, int>(reader.ReadString(), "OUT3", 9));
break;
}
}
}
for (int i = 0; i < values.Count; i++)
{
for (int j = 0; j < values.Count; j++)
{
if (i == values[j].Item3)
{
data.AddRange(new List<Data> { new Data { Type = values[j].Item2, Value = values[j].Item1 } });
}
}
}
return data;
}
很可能与这段代码有关:
WebRequest request = WebRequest.Create("http://192.168.1.100/st0.xml");
您正在调用一个本地 IP 地址,如果它是在共享主机上,它可能不会喜欢这个请求。
我已经解决了这些问题。
找到解决方案后,我通过以下步骤编辑了 Web.config 中的代码:
<location path="." inheritInChildApplications="false">
<system.web>
...
...
...
</system.web>
</location>
下次可以帮到别人。