Пустая ссылка исключение при генерации URL с методом UrlHelper.Action

По какой-то причине, когда определенные боты посещают сайт, генерируя URL сUrlHelper.Action метод вызывает нулевое исключение изSystem.Web.HttpServerVarsCollection.Get, Я сделал некоторую отладку, и стек вызовов начинается с попытки получить HTTP_X_ORIGINAL_URL отHttpContextBase.Request.ServerVariables коллекция.

Если я захожу на тот же адрес прямо из браузера - нет проблем. Страница является серверной, и ошибка не регистрируется. Кажется, это происходит только при посещении ботом.

Не уверен, что это актуально или нет, но сайт был только что перенесен в IIS 7.5. Все еще использую .NET 2.0 в интегрированном режиме.

Рассматривая код как обратный с помощью Reflector, единственное место, где нулевое исключение может возникнуть непосредственно вGet метод это вызовthis._request.FetchServerVariables, Как будто полный запрос не был настроен должным образом.

Кто-нибудь еще сталкивался с этой проблемой или обнаружил обходной путь? Почему запрос будет установлен по-разному при посещении ботом?

ОБНОВИТЬДополнительная отладка показала, что объект HttpServerVarsCollection был удален вместе с его родительским объектом HttpRequest. Теперь возникает вопрос - как можно представить объект Request, возвращенный HttpContext.Current, до завершения запроса?

Метод 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:\Dev\Site\MVC\Microsoft\src\SystemWebMvc\Mvc\PathHelpers.cs:39
   System.Web.Mvc.PathHelpers.GenerateClientUrl(HttpContextBase httpContext, String contentPath) in C:\Dev\Site\MVC\Microsoft\src\SystemWebMvc\Mvc\PathHelpers.cs:21
   System.Web.Mvc.UrlHelper.GenerateUrl(String routeName, String actionName, String controllerName, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, Boolean includeImplicitMvcValues) in C:\Dev\Site\MVC\Microsoft\src\SystemWebMvc\Mvc\UrlHelper.cs:136
   System.Web.Mvc.UrlHelper.GenerateUrl(String routeName, String actionName, String controllerName, RouteValueDictionary routeValues) in C:\Dev\Site\MVC\Microsoft\src\SystemWebMvc\Mvc\UrlHelper.cs:101
   System.Web.Mvc.UrlHelper.Action(String actionName, String controllerName, Object routeValues) in C:\Dev\Site\MVC\Microsoft\src\SystemWebMvc\Mvc\UrlHelper.cs:51
   www.CmsExtensions.Document(UrlHelper urlHelper, String path) in C:\Dev\Site\www\Code\CmsExtensions.cs:33
   www.CmsExtensions.Document(UrlHelper urlHelper, Document document) in C:\Dev\Site\www\Code\CmsExtensions.cs:20
   www.<>c__DisplayClass17.<Load>b__c(Document d) in C:\Dev\Site\www\Global.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 count, Int32 startat) +28
   System.Text.RegularExpressions.Regex.Replace(String input, MatchEvaluator evaluator) +38
   System.Text.RegularExpressions.Regex.Replace(String input, String pattern, MatchEvaluator evaluator, 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:\Dev\Site\MVC\Microsoft\src\SystemWebMvc\Mvc\ViewPage.cs:107
   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.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266

Ответы на вопрос(3)

Ваш ответ на вопрос