0

I have encountered an error for which I can find no answer online. I created a new virtual Server 2008 R2 Standard box with the IIS role and ASP.NET role services. The server is destined for production. I copied a website to the server and it has ceased to work; Specifically, the RoleManagerModule is throwing a NullReferenceException. This happens on any *.aspx page, but not static pages such as robots.txt. This error happens even for pages which don't have any authorization rules. Here are relevant snippets from the error in the application event log:

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)

This only happens if the Role Manager is enabled in the web.config as such:

<roleManager defaultProvider="EWRO" enabled="true">

If I remove or set to false the enabled attribute, the aspx pages respond properly. I have matched as close as possible the configuration and installed services of the server on which the website is currently running. You may notice that I have a custom Role Provider, however the same exception happens even if I remove the defaultProvider attribute. The AspNetSqlRoleProvider would fail anyway, but it does not reach that point.

A solution or steps to find a solution would be much appreciated.

Norm
  • 1
  • 1

2 Answers2

0

I ended up re-installing the IIS Server role and it fixed the issue. Sorry I couldn't be more help to any others who find this issue.

Norm
  • 1
  • 1
0

This error occurs because RoleManager cannot find an user identity, usually when anonymous authentication enabled.

To resolve it try to edit

c:\windows\system32\inetsrv\config\applicationHost.config

and put DefaultAuthenticationModule before RoleManagerModule

<add name="DefaultAuthentication" type="System.Web.Security.DefaultAuthenticationModule" preCondition="managedHandler" />
<add name="RoleManager" type="System.Web.Security.RoleManagerModule" preCondition="managedHandler" />
Tiago Martins Peres
  • 14,289
  • 18
  • 86
  • 145