.net – 使用UrlHelper.Action方法生成网址时,引用异常
发布时间:2020-12-15 23:43:13 所属栏目:asp.Net 来源:网络整理
导读:由于某些原因,当某些机器人访问该站点时,使用UrlHelper.Action方法生成URL将从System.Web.HttpServerVarsCollection.Get引发一个空异常.我做了一些调试,调用堆栈起源于尝试从HttpContextBase.Request.ServerVariables集合获
由于某些原因,当某些机器人访问该站点时,使用UrlHelper.Action方法生成URL将从System.Web.HttpServerVarsCollection.Get引发一个空异常.我做了一些调试,调用堆栈起源于尝试从HttpContextBase.Request.ServerVariables集合获取“HTTP_X_ORIGINAL_URL”.
如果我直接从浏览器访问相同的地址 – 没有问题.该页面是服务器,没有记录错误.它似乎只是在机器人访问时才发生. 不确定是否相关,但该网站刚刚迁移到IIS 7.5.仍然在集成模式下使用.NET 2.0. 看看Reflector反转的代码,唯一可以直接在Get方法中发生空异常的地方是调用this._request.FetchServerVariables.好像完整的请求没有正确设置. 有没有人面临这个问题或发现了一个解决方法?为什么在机器人访问时请求的设置会有所不同? 更新:一些额外的调试已经显示HttpServerVarsCollection被Dispose,以及它的父HttpRequest对象.现在的问题是 – HttpContext.Current返回的Request对象在请求完成之前如何被暴露? HttpServerVarsCollection.Get方法 public override string Get(string name) { if (!this._populated) { string simpleServerVar = this.GetSimpleServerVar(name); if (simpleServerVar != null) { return simpleServerVar; } this.Populate(); } if (this._iis7workerRequest == null) { return this.GetServerVar(base.BaseGet(name)); } string serverVar = this.GetServerVar(base.BaseGet(name)); if (string.IsNullOrEmpty(serverVar)) { // Only place null reference can happen serverVar = this._request.FetchServerVariable(name); } return serverVar; } 全堆栈跟踪 NullReferenceException: Object reference not set to an instance of an object.] System.Web.HttpServerVarsCollection.Get(String name) +8645730 System.Collections.Specialized.NameValueCollection.get_Item(String name) +7 System.Web.Mvc.PathHelpers.GenerateClientUrlInternal(HttpContextBase httpContext,String contentPath) in C:DevSiteMVCMicrosoftsrcSystemWebMvcMvcPathHelpers.cs:39 System.Web.Mvc.PathHelpers.GenerateClientUrl(HttpContextBase httpContext,String contentPath) in C:DevSiteMVCMicrosoftsrcSystemWebMvcMvcPathHelpers.cs:21 System.Web.Mvc.UrlHelper.GenerateUrl(String routeName,String actionName,String controllerName,RouteValueDictionary routeValues,RouteCollection routeCollection,RequestContext requestContext,Boolean includeImplicitMvcValues) in C:DevSiteMVCMicrosoftsrcSystemWebMvcMvcUrlHelper.cs:136 System.Web.Mvc.UrlHelper.GenerateUrl(String routeName,RouteValueDictionary routeValues) in C:DevSiteMVCMicrosoftsrcSystemWebMvcMvcUrlHelper.cs:101 System.Web.Mvc.UrlHelper.Action(String actionName,Object routeValues) in C:DevSiteMVCMicrosoftsrcSystemWebMvcMvcUrlHelper.cs:51 www.CmsExtensions.Document(UrlHelper urlHelper,String path) in C:DevSitewwwCodeCmsExtensions.cs:33 www.CmsExtensions.Document(UrlHelper urlHelper,Document document) in C:DevSitewwwCodeCmsExtensions.cs:20 www.<>c__DisplayClass17.<Load>b__c(Document d) in C:DevSitewwwGlobal.asax.cs:251 Fringine.Cms.DocumentContentParser.ReplaceDocumentRefs(IResolvingDocumentCache cache,Match match) +258 Fringine.Cms.<>c__DisplayClass4.<ParseContent>b__2(Match m) +17 System.Text.RegularExpressions.RegexReplacement.Replace(MatchEvaluator evaluator,Regex regex,String input,Int32 count,Int32 startat) +234 System.Text.RegularExpressions.Regex.Replace(String input,MatchEvaluator evaluator,Int32 startat) +28 System.Text.RegularExpressions.Regex.Replace(String input,MatchEvaluator evaluator) +38 System.Text.RegularExpressions.Regex.Replace(String input,String pattern,RegexOptions options) +47 Fringine.Cms.DocumentContentParser.ParseContent(String content,IResolvingDocumentCache cache) +83 Fringine.Cms.ResolvingDocumentCache.<Parse>b__0(String d) +21 Fringine.Cms.DocumentCache.GetParsedData(String id,String content,IDocumentService documentService,Func`2 parser) +216 Fringine.Cms.ResolvingDocumentCache.Parse(String id,String content) +67 Fringine.Cms.CachedDocument.GetSummary() +966 Fringine.Cms.CachedDocument.get_Summary() +19 ASP.views_document_widget_feeddocumentsummary_ascx.__Render__control1(HtmlTextWriter __w,Control parameterContainer) +841 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,ICollection children) +256 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19 System.Web.UI.Control.Render(HtmlTextWriter writer) +10 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,ControlAdapter adapter) +27 System.Web.UI.Control.RenderControl(HtmlTextWriter writer,ControlAdapter adapter) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,ICollection children) +134 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19 System.Web.UI.Page.Render(HtmlTextWriter writer) +29 System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) in C:DevSiteMVCMicrosoftsrcSystemWebMvcMvcViewPage.cs:107 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,ControlAdapter adapter) +99 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) +1266 解决方法
我有这个问题,但它与URL重写模块无关.
在我的情况下,我不小心在静态字段中缓存了UrlHelper的一个实例,后来的请求从先前的请求中遇到了一个已处理的实例. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
推荐文章
站长推荐
- ASP.NET 4.0删除控件后菜单控件的渲染问题Render
- asp.net-mvc – 使用ASP.NET MVC,如何在外部控制
- 在Docker上部署自动更新ssl证书的nginx + .NET C
- asp.net-mvc – 使用ui-router的.NET MVC和Angul
- asp.net-mvc – 我可以在ASP.NET MVC 4中更改web
- asp.net – AcquireRequestState的长时间延迟
- asp.net-mvc – ASP.Net MVC – Img Src服务器路
- asp.net – Windows 10主页:Windows身份验证
- asp.net-mvc – MVC架构 – 重新使用相同的viewm
- asp.net-mvc – Asp .Net Core – 无法安装Micro
热点阅读