asp.net-mvc - ASP MVC.NET3 本地 IIS7 对象引用错误

标签 asp.net-mvc iis-7

在开发 mvc Web 应用程序期间,我遇到了运行站点本地实例的问题。当我尝试重新加载页面时,在首次加载成功后,我看到以下错误。如果我通过 VS 虚拟服务器运行该站点,则没有问题。我的应用程序池在集成模式下运行,并且正在运行 .net 4。知道为什么会发生这种情况吗?这是足够的信息吗?

[NullReferenceException: Object reference not set to an instance of an object.] System.Web.HttpServerVarsCollection.Get(String name) +109 System.Web.Mvc.UrlRewriterHelper.WasThisRequestRewritten(HttpContextBase httpContext) +59 System.Web.Mvc.PathHelpers.GenerateClientUrlInternal(HttpContextBase httpContext, String contentPath) +213 System.Web.Mvc.PathHelpers.GenerateClientUrlInternal(HttpContextBase httpContext, String contentPath) +168 System.Web.Mvc.PathHelpers.GenerateClientUrl(HttpContextBase httpContext, String contentPath) +148 LeadManager.Web.UI.Helpers.MenuHelper.GenerateUrl(String url) in C:\Development\Hg\LeadManager\Web.UI\Helpers\MenuHelper.cs:1132 LeadManager.Web.UI.Helpers.MenuHelper.BuildLeadManagementMenu(Menu navMenu, Agent agent) in C:\Development\Hg\LeadManager\Web.UI\Helpers\MenuHelper.cs:554 LeadManager.Web.UI.Helpers.MenuHelper.AddNavMenu(Agent agent) in C:\Development\Hg\LeadManager\Web.UI\Helpers\MenuHelper.cs:530 ASP._Page_Views_Shared__Layout_cshtml.Execute() in c:\Development\Hg\LeadManager\Web\Views\Shared_Layout.cshtml:115 System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +279 System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +103 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +172 System.Web.WebPages.WebPageBase.Write(HelperResult result) +88 System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action1 body) +233 System.Web.WebPages.WebPageBase.PopContext() +233 System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +377 System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +32 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func1 continuation) +748196 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func1 continuation) +748196 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1 filters, ActionResult actionResult) +265 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +748160 System.Web.Mvc.Controller.ExecuteCore() +159 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +334 System.Web.Mvc.<>c_DisplayClassb.b_5() +62 System.Web.Mvc.Async.<>c_DisplayClass1.b_0() +15 System.Web.Mvc.<>c_DisplayClasse.b_d() +52 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +437 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +354



MenuHelper 用于构建导航菜单。失败的代码是 if 之外的 return 语句:
private static string GenerateUrl(string url)
{
    if (instance == null)
    {
        // hack to enable using this on old web forms pages
        return UrlHelper.GenerateContentUrl(url, new HttpContextWrapper(HttpContext.Current));
    }
    return (new UrlHelper(instance.htmlHelper.ViewContext.RequestContext)).Content(url);
}

private static string GenerateUrl(string actionName, string controllerName)
{
    if (instance == null)
    {
        // hack to enable using this on old web forms pages
        return GenerateUrl(String.Format("{0}/{1}", controllerName, actionName));
    }

    if (instance.htmlHelper == null)
        throw new InvalidOperationException("htmlHelper has not been populated.");
    if (instance.htmlHelper.ViewContext == null)
        throw new InvalidOperationException("ViewContext has not been populated.");
    if (instance.htmlHelper.ViewContext.RequestContext == null)
        throw new InvalidOperationException("RequestContext has not been populated.");

    UrlHelper urlHelper = new UrlHelper(instance.htmlHelper.ViewContext.RequestContext);
    if (urlHelper == null)
        throw new InvalidOperationException("UrlHelper has not been populated.");

    if (String.IsNullOrEmpty(actionName))
        throw new InvalidOperationException("actionName has not been populated.");
    if (String.IsNullOrEmpty(controllerName))
        throw new InvalidOperationException("controllerName has not been populated.");

    return (urlHelper.Action(actionName, controllerName));
}

最佳答案

我发现了问题,它是 IIS7 URL 重写模块。我不确定为什么或如何,但我通过卸载它解决了这个问题。

关于asp.net-mvc - ASP MVC.NET3 本地 IIS7 对象引用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8996067/

相关文章:

asp.net - 可以在不破坏网站的情况下将 MIME 类型添加到 web.config 中吗?

c# - C# 中的帧重定向

iis - 在 IIS 中设置重定向并保留参数

asp.net-mvc - ASP.NET MVC 4 - 模态保存后使用子操作重定向

asp.net-mvc - UseJwtBearerAuthentication 在 token 过期时返回 HTTP 500

asp.net-mvc - .net mvc 的简短/快速解释

javascript - window.history.back() 在 CSHTML 页面中不起作用

c# - 如何以编程方式为 IIS7 创建子域?

asp.net-mvc-2 - Application_BeginRequest() 之前的 ASP.NET 间歇性滞后

c# - 模型将集合属性与局部 View 绑定(bind)