[Authorize] public contentresult Index2 () { return Content ( " the validation passed " );
It is often possible to see an action under a controler to verify the state of the login permission through this tag, otherwise the action will not execute. But what conditions can be met to pass authorize this filter to check it? Answer: ↓
Publicwebapiapplication () {postauthenticaterequest+=webapiapplication_postauthenticaterequest; } /// <summary> ///gets the user's identity information/// </summary> /// <param name= "Sender" ></param> /// <param name= "E" ></param> Private voidWebapiapplication_postauthenticaterequest (Objectsender, EventArgs e) { //Authentication Logic//Key CodeHttpContext.Current.User =NewMyUser () {code ="Admin", name ="Admin" }; }
Add the following code to the Global.asax. This means that in the application pipeline event, "Get the user identity information" in the event, obtain the user identity information and verify, give HttpContext.Current.User assignment. It is important to note that the myuser needs to implement the IPrincipal interface.
Sentiment:
Every day is talking about a variety of advanced technology, all kinds of loading force, the simplest basic applications are not know, code with a half-day to find, the problem is asked a circle do not know, hey ...
Standard for the simplest authentication of ASP. NET MVC [authorize]