Home > Net >  In the Global. Asax obtains the Context. The User why is empty?
In the Global. Asax obtains the Context. The User why is empty?

Time:11-25

Refer to this blog
https://www.cnblogs.com/asks/p/4372783.html
Forms authentication is added in the MVC, useless wizard to add, because the and I can't match the original database,
Modify Globl. Asax
 
Public class MvcApplication: System. Web. HttpApplication
{
Public MvcApplication ()
{
AuthorizeRequest +=new EventHandler (MvcApplication_AuthorizeRequest);
}

Void MvcApplication_AuthorizeRequest (object sender, EventArgs e)
{
IIdentity id=Context, User Identity;//test for the first time into will be stuck in this way, prompt null values,
If (id. IsAuthenticated)
{
Var roles=new UserRepository (). The GetRoles (id) Name);
The Context. The User=new GenericPrincipal (id, roles);
}
}
//...
}

Then I used the if (Context. The User!=null) skip this sentence, want to question and bosses, if this sentence itself has a problem, or need to change in other places can pass?

CodePudding user response:

The corresponding application pool managed pipeline mode try to classic

CodePudding user response:

Is to use VS own web server test, not deployed in IIS
  • Related