forms-authentication – ASP.NET MVC5应用程序在授权时抛出Null
发布时间:2020-12-16 06:33:13 所属栏目:asp.Net 来源:网络整理
导读:我有一个MVC5应用程序在使用控制器上的[Authorize]属性时在生产服务器上抛出NullReferenceException.该应用程序正在使用表单身份验 生产服务器是Server 2008 SP 2(.NET 4.5.1和IIS 7). 堆栈跟踪的开始是: [NullReferenceException: Object reference not se
我有一个MVC5应用程序在使用控制器上的[Authorize]属性时在生产服务器上抛出NullReferenceException.该应用程序正在使用表单身份验
生产服务器是Server 2008 SP 2(.NET 4.5.1和IIS 7). 堆栈跟踪的开始是: [NullReferenceException: Object reference not set to an instance of an object.] System.Web.Mvc.AuthorizeAttribute.AuthorizeCore(HttpContextBase httpContext) +38 System.Web.Mvc.AuthorizeAttribute.OnAuthorization(AuthorizationContext filterContext) +293 System.Web.Mvc.ControllerActionInvoker.InvokeAuthorizationFilters(ControllerContext controllerContext,IList`1 filters,ActionDescriptor actionDescriptor) +155 我可以通过设置来修复它 <modules runAllManagedModulesForAllRequests="true"> 但是,我不想使用这样的sledgehammer method. 有没有更清洁的方法来解决这个问题? 解决方法
IIS和IIS Express对请求身份验证有一些不同的行为.由于验证模块并不总是运行,因此当AuthorizeAttribute.AuthorizeCore()方法执行时(因此NullReferenceException),可能无法设置HttpContext.User.Identity属性.
您可以仅更改所需的身份验证模块的前提条件,而不是为所有请求加载所有模块.例如,FormsAuthenticationModule默认具有:preCondition =“managedHandler”. <system.webServer> <modules runAllManagedModulesForAllRequests="false"> <remove name="FormsAuthentication" /> <remove name="DefaultAuthentication" /> <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" preCondition="" /> <add name="DefaultAuthentication" type="System.Web.Security.DefaultAuthenticationModule" preCondition="" /> </modules> </system.webServer> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET MVC 开源项目Kigg解读(1)
- JQGrid分组GroupText格式和修改
- asp.net-mvc-2 – 从.NET MVC 1迁移到MVC 2 RC
- asp.net – 需要一个必须同时具有数字和字母字符的字符串的
- asp.net – 如何以编程方式配置ELMAH?
- asp.net-mvc-2 – 在发布网站后无法在asp.net mvc2中加载类
- asp.net-mvc – ASP.NET MVC剃刀视图引擎默认编码HTML吗?
- asp.net – 在Windows身份验证开启时使用ajax调用Web服务?
- asp.net-mvc-3 – 如何在MVC3中格式化小数超过2位小数
- asp.net-mvc-5 – 如何使用asp.net身份更改当前用户的UserN
推荐文章
站长推荐
- ASP.NET MVC4模型验证
- asp.net-mvc – “一个MVC过滤器提供程序已经注册
- asp.net – 尝试设置此报告中未定义的报告参数“
- asp.net – ADFS 2.0超时以及Freshness Value,To
- asp.net – Web.config文件中的appSettings和con
- ASP.NET 4.0中最好的浏览器检测解决方案
- 在ASP.NET AJAX中动态添加控件到UpdatePanel
- ASP.Net将文件下载到客户端浏览器
- asp.net-mvc – 从ASP.NET MVC2升级到MVC3的原因
- asp.net – RouteTable.Routes和HttpConfigurati
热点阅读