/// <summary>
/// 通过URL执行WEN后获取页面内容
/// </summary>
/// <param name="url"></param>
public static string ExecutePage(string urlstr)
{
string content = ""; if (urlstr.IndexOf("http://", StringComparison.OrdinalIgnoreCase) != 0 && urlstr.IndexOf("/") == 0)
{
urlstr = "http://" + HttpContext.Current.Request.Url.Host + urlstr;
}
else if (urlstr.IndexOf("http://", StringComparison.OrdinalIgnoreCase) != 0)
{
urlstr = "http://" + urlstr;
} System.Net.WebResponse wResp = null;
System.IO.Stream respStream = null;
System.IO.StreamReader reader = null;
try
{
Uri url = new Uri(urlstr);
System.Net.WebRequest wReq = System.Net.WebRequest.Create(url);
wResp = wReq.GetResponse();
respStream = wResp.GetResponseStream();
reader = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding("utf-8"));
content = reader.ReadToEnd();
}
catch (System.Net.WebException ex)
{
//return ex.Source + ":" + urlstr;
throw;
}
finally
{
if (reader!= null)
reader.Close();
if (respStream != null)
respStream.Close();
if (wResp != null)
wResp.Close(); }
return content;
}调用ExecutePage("http://www.163.com") 正常。调用ExecutePage("http://localhost") 正常。调用ExecutePage("http://localhost/ReviewBox/ReviewArticle.aspx?id=1") 报错。http://localhost/ReviewBox/ReviewArticle.aspx?id=1 正常显示.
/// 通过URL执行WEN后获取页面内容
/// </summary>
/// <param name="url"></param>
public static string ExecutePage(string urlstr)
{
string content = ""; if (urlstr.IndexOf("http://", StringComparison.OrdinalIgnoreCase) != 0 && urlstr.IndexOf("/") == 0)
{
urlstr = "http://" + HttpContext.Current.Request.Url.Host + urlstr;
}
else if (urlstr.IndexOf("http://", StringComparison.OrdinalIgnoreCase) != 0)
{
urlstr = "http://" + urlstr;
} System.Net.WebResponse wResp = null;
System.IO.Stream respStream = null;
System.IO.StreamReader reader = null;
try
{
Uri url = new Uri(urlstr);
System.Net.WebRequest wReq = System.Net.WebRequest.Create(url);
wResp = wReq.GetResponse();
respStream = wResp.GetResponseStream();
reader = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding("utf-8"));
content = reader.ReadToEnd();
}
catch (System.Net.WebException ex)
{
//return ex.Source + ":" + urlstr;
throw;
}
finally
{
if (reader!= null)
reader.Close();
if (respStream != null)
respStream.Close();
if (wResp != null)
wResp.Close(); }
return content;
}调用ExecutePage("http://www.163.com") 正常。调用ExecutePage("http://localhost") 正常。调用ExecutePage("http://localhost/ReviewBox/ReviewArticle.aspx?id=1") 报错。http://localhost/ReviewBox/ReviewArticle.aspx?id=1 正常显示.
调用ExecutePage("http://localhost/ReviewBox/ReviewArticle.aspx");同样问题。
System.Net.WebRequest wReq = System.Net.WebRequest.Create(url);你看下你的url地址是什麼!
再检查
也是允许的。
{
if (!IsPostBack)
{
string artNO = this.Request["articleNO"];
if (artNO == null || artNO == "")
{
return;
//这里我就退出去了,不知这样可以吗?
}
modelart = bllart.GetModel(artNO);
if (modelart == null)
{
return;
}
}
}
System.IO.Stream respStream = null;
System.IO.StreamReader reader = null;
try
{
Uri url = new Uri(urlstr);
System.Net.WebRequest wReq = System.Net.WebRequest.Create(url);
wResp = (HttpWebResponse)wReq.GetResponse();
respStream = wResp.GetResponseStream();
reader = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding("utf-8"));
content = reader.ReadToEnd();
}
catch (System.Net.WebException ex)
{
//return ex.Source + ":" + urlstr;
throw;
}
http://topic.csdn.net/t/20020924/14/1049079.html
<html>
<head>
<title>未将对象引用设置到对象的实例。</title>
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: .9em}
.er {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
</style>
</head> <body bgcolor="white"> <span><H1>“/”应用程序中的服务器错误。<hr width=100% size=1 color=silver></H1> <h2> <i>未将对象引用设置到对象的实例。</i> </h2></span> <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "> <b> 说明: </b>执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 <br><br> <b> 异常详细信息: </b>System.NullReferenceException: 未将对象引用设置到对象的实例。<br><br> <b>源错误:</b> <br><br> <table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code>执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。</code> </td>
</tr>
</table> <br> <b>堆栈跟踪:</b> <br><br> <table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code><pre>[NullReferenceException: 未将对象引用设置到对象的实例。]
FredCK.FCKeditorV2.FCKeditor.IsCompatibleBrowser(HttpRequest request) in C:\Documents and Settings\xsasa\桌面\FCKeditor.Net_2.6.3\FCKeditor.cs:494
FredCK.FCKeditorV2.FCKeditor.IsCompatibleBrowser() in C:\Documents and Settings\xsasa\桌面\FCKeditor.Net_2.6.3\FCKeditor.cs:476
FredCK.FCKeditorV2.FCKeditor.CheckBrowserCompatibility() in C:\Documents and Settings\xsasa\桌面\FCKeditor.Net_2.6.3\FCKeditor.cs:466
FredCK.FCKeditorV2.FCKeditor.OnPreRender(EventArgs e) in C:\Documents and Settings\xsasa\桌面\FCKeditor.Net_2.6.3\FCKeditor.cs:400
System.Web.UI.Control.PreRenderRecursiveInternal() +80
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
</pre></code> </td>
</tr>
</table> <br> <hr width=100% size=1 color=silver> <b>版本信息:</b> Microsoft .NET Framework 版本:2.0.50727.3053; ASP.NET 版本:2.0.50727.3053 </font> </body>
</html>
<!--
[NullReferenceException]: 未将对象引用设置到对象的实例。
在 FredCK.FCKeditorV2.FCKeditor.IsCompatibleBrowser(HttpRequest request) 位置 C:\Documents and Settings\xsasa\桌面\FCKeditor.Net_2.6.3\FCKeditor.cs:行号 494
在 FredCK.FCKeditorV2.FCKeditor.IsCompatibleBrowser() 位置 C:\Documents and Settings\xsasa\桌面\FCKeditor.Net_2.6.3\FCKeditor.cs:行号 476
在 FredCK.FCKeditorV2.FCKeditor.CheckBrowserCompatibility() 位置 C:\Documents and Settings\xsasa\桌面\FCKeditor.Net_2.6.3\FCKeditor.cs:行号 466
在 FredCK.FCKeditorV2.FCKeditor.OnPreRender(EventArgs e) 位置 C:\Documents and Settings\xsasa\桌面\FCKeditor.Net_2.6.3\FCKeditor.cs:行号 400
在 System.Web.UI.Control.PreRenderRecursiveInternal()
在 System.Web.UI.Control.PreRenderRecursiveInternal()
在 System.Web.UI.Control.PreRenderRecursiveInternal()
在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
[HttpUnhandledException]: 引发类型为“System.Web.HttpUnhandledException”的异常。
在 System.Web.UI.Page.HandleError(Exception e)
在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
在 System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
在 System.Web.UI.Page.ProcessRequest()
在 System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
在 System.Web.UI.Page.ProcessRequest(HttpContext context)
在 ASP.reviewbox_reviewarticle_aspx.ProcessRequest(HttpContext context) 位置 c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\7fbc70ed\63e50afc\App_Web_pfnvaqdh.0.cs:行号 0
在 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
在 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
[HttpException]: Unhandled HttpException while processing NeatUpload child request
在 Brettle.Web.NeatUpload.UploadHttpModule.Application_BeginRequest(Object sender, EventArgs e)
在 System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
在 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
-->