我遇到一个错误,无法在线找到答案。我使用IIS角色和ASP.NET角色服务创建了一个新的虚拟Server 2008 R2 Standard框。该服务器将用于生产。我将网站复制到服务器,但该网站已停止工作;具体而言,RoleManagerModule引发NullReferenceException。这会在任何* .aspx页面上发生,但不会在静态页面(例如robots.txt)上发生。即使没有任何授权规则的页面也会发生此错误。以下是应用程序事件日志中错误的相关摘要:
Exception information:
Exception type: NullReferenceException
Exception message: Object reference not set to an instance of an object.
Request information:
Request URL: ********
Request path: /
User host address: ********
User:
Is authenticated: False
Authentication Type:
Thread account name: ********
Thread information:
Thread ID: 8
Thread account name: ********
Is impersonating: False
Stack trace: at System.Web.Security.RoleManagerModule.OnEnter(Object source, EventArgs eventArgs)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
仅在像这样在web.config中启用了角色管理器时,才会发生这种情况:
<roleManager defaultProvider="EWRO" enabled="true">
如果我删除已启用的属性或将其设置为false,则aspx页面会正确响应。我已经尽可能匹配了当前正在运行网站的服务器的配置和安装服务。您可能会注意到我有一个自定义的角色提供程序,但是即使删除了defaultProvider属性,也会发生相同的异常。无论如何,AspNetSqlRoleProvider都会失败,但仍达不到这一点。
非常感谢您提供解决方案或找到解决方案的步骤。
我最终重新安装了IIS服务器角色,它解决了该问题。抱歉,找到这个问题的其他人将无济于事。
发生此错误是因为RoleManager通常在启用匿名身份验证时找不到用户身份。
要解决它,请尝试编辑
c:\ windows \ system32 \ inetsrv \ config \ applicationHost.config
并将DefaultAuthenticationModule放在RoleManagerModule之前
<add name="DefaultAuthentication" type="System.Web.Security.DefaultAuthenticationModule" preCondition="managedHandler" />
<add name="RoleManager" type="System.Web.Security.RoleManagerModule" preCondition="managedHandler" />