If you have tried ASP. net mvc 4, you will surely notice this change in accountcontroller:
[Authorize]
Public ClassAccountcontroller: Controller
{
//
//Get:/account/logon
[Allowanonymous]
PublicActionresult Logon ()
{
ReturnContextdependentview ();
}
}
In this sectionCodeThe difference between them and MVC 3 is that the authorize filter is added to all actions in accountcontroller, and the action that allows direct access is added with allowanonymous. This is not to mention. Next, rabbit paper encountered a tough problem,
All of us have a powerful function in ASP. net mvc 3.0, that is, remote. You can remotely interact with the database to verify the model. For example, you can verify whether the user name is repeated during registration. I don't need to talk about it anymore. I can check it online. Paste the code here:
[Remote ("Checkusernameexists","Account", Errormessage ="Sorry! In the registered members the name already exists. Please enter a different name.")]
[Display (name ="User Name")]
Public StringUsername {Get;Set;}
[Httpget] // you can only use get !!! Public actionresult checkusernameexists (string username) // remotely verify whether username is repeated {dataentities EF = new dataentities (); // instantiate EF var itemtitle = EF. users. where (C => C. username = username); bool exists = itemtitle. count () <1 = false; return JSON (! Exists, jsonrequestbehavior. allowget );}
Both of them are very good and powerful, but when they are together, it's time to get the remote. I checked several times and found no problem. Later I thought of the reason why all the actions in accountcontroller in MVC 4 were added with authorize. therefore, allowanonymous is added to the preceding checkusernameexists action. finally.
In programming, there will always be such a tough thing, but as long as you stick to it, I believe it will soon not hurt.