MVC5 website development practice 2.2, Administrator authentication, mvc52.2
The last time the Administrator logs on, the AuthorizeAttribute is used to verify the Administrator logs on. A few issues need to be solved before the verification class is rewritten, and the interface is slightly changed.
Directory
Overview of MVC5 website development practices
MVC5 website development practices 1. Create a project
MVC5 website development practices 2. Background Management
MVC5 website development practice 2.1. Log On As an administrator
I. troubleshooting Home controller error prompt
@ Ted said in the comment that the following error exists in the browser. This is because there are multiple Home controllers in the project, but the system does not know which controller you want to access. Therefore, you need to add a namespace for each route.
Using System. web; using System. web. mvc; namespace Ninesky. website. areas. config {/// <summary> /// administrator authentication /// <remarks> /// create: december 16, 2014 /// </remarks> /// </summary> public class AdminAuthorizeAttribute: AuthorizeAttribute {protected override bool AuthorizeCore (HttpContextBase httpContext) {bool _ pass = false; if (httpContext. session ["Account"]! = Null) _ pass = true; return _ pass;} protected override void HandleUnauthorizedRequest (AuthorizationContext filterContext) {filterContext. Result = new RedirectResult ("~ /Config/Administrator/Login ");}}}
2. Add verification attributes to the Controller
Open the Homecontroller In the config area and add the "AdminAuthorize" attribute to the Controller.
@ Model Ninesky. Website. Areas. Config. Models. LoginViewModel @ {Layout = null;} <! DOCTYPE html>
The modified logon page.
<! DOCTYPE html>
Now you can see the logon page.
======================================
Code: http://pan.baidu.com/s/1ntt9gKT