I have the [Authorize] attribute on the HomeController , whenever I try to access it, it throws a NullReferenceException
This is really strange because I used [Authorize] many times before and it works great. The only difference in this case is that this application is hosted on our own web server using Windows 7 and IIS 7.5
Here is the stack trace:
[NullReferenceException: object reference not set to instance object.]
System.Web.Mvc.AuthorizeAttribute.AuthorizeCore (HttpContextBase httpContext) +38
System.Web.Mvc.AuthorizeAttribute.OnAuthorization (AuthorizationContext filterContext) +160
System.Web.Mvc.ControllerActionInvoker.InvokeAuthorizationFilters (ControllerContext controlContext, IList`1, ActionDescriptor actionDescriptor) +155
System.Web.Mvc.ControllerActionInvoker.InvokeAction (ControllerContext controllerContext, String actionName) +784976
System.Web.Mvc.Controller.ExecuteCore () +159
System.Web.Mvc.ControllerBase.Execute (RequestContext requestContext) +335 System.Web.Mvc. <> c_DisplayClassb.b_5 () +62
System.Web.Mvc.Async. <> c_DisplayClass1.b_0 () +20
System.Web.Mvc. <> c_DisplayClasse.b_d () +54
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute () +453 System.Web.HttpApplication.ExecuteStep (step IExecutionStep, Logical & completed synchronously) +371
Edit:
Studying the code of the AuthorizeCore method, it seems that AuthorizeCore throws a NullReferenceException because it gets a NULL HttpContextBase .
Is it possible? Since everything else in the application works very well, for example, accessing the database, creating cookies, etc.
Edit 2:
This only happens after publishing to the web server. Although development, it works great with Visual Studio.
Charandeep singh
source share