"Building a Mvc+log4net+knockout+easyui+fluentdata+sqlite framework from scratch" X, implementation of login module

Source: Internet
Author: User
Tags sqlite log4net

First, the use of actionfilterattribute to achieve rights management

1. Create a menu filter class

//Building a Permissions menu filter     Public classMvcmenufilter:actionfilterattribute {Private BOOL_isenable =true;//whether to turn on filtering         PublicMvcmenufilter () {_isenable =true; }//Constructor 1, open by default         PublicMvcmenufilter (BOOLisenable) {_isenable = isenable;}//Constructor 2, specifying whether to open the//rewrite onactionexecuting         Public Override voidonactionexecuting (ActionExecutingContext filtercontext) {if(_isenable)//If filtering is turned on            {                //gets the currently executing address                varRoute =filterContext.RouteData.Values; varURL =string. Format ("/{0}/{1}/{2}", route[" Area"], route["Controller"], route["Action"]); //access the database to check if the current user has this permission                if(!NewSys_userservice (). Authorizeusermenu (URL)) Filtercontext.result=NewContentresult () {Content ="you do not have permission to access this feature, please contact the administrator! " }; }            //Perform access            Base.        OnActionExecuting (Filtercontext); }    }

2. Add this filter to the filter configuration file, then all actions will pass through this filter

 Public classFilterconfig { Public Static voidregisterglobalfilters (globalfiltercollection filters) {filters. ADD (NewMvchandleerrorattribute ()); //filters.            ADD (New System.Web.Mvc.AuthorizeAttribute ()); //filters. ADD (New Mvcdisposefilter ());Filters. ADD (NewMvcmenufilter ());//Join the Permissions menu filter        }    }

3, the configuration file Web. config in the <system.web> to join the following node, validation failed to jump to that address

Content reference: Https://msdn.microsoft.com/zh-cn/library/532aee0e.aspx

Question: Does this and the above prompt conflict

    <mode= "Forms">      <loginurl  = "~/login"  timeout= "2880"/>    </Authentication  >

  

"Building a Mvc+log4net+knockout+easyui+fluentdata+sqlite framework from scratch" X, implementation of login module

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.