ASP. NET MVC claimsidentity Authorization Study (or Beta bug)

Source: Internet
Author: User

Installation

Microsoft.Owin.Host.SystemWeb

Identity.core

Microsoft.Owin.Security.Cookies

In is Startup.cs make the following changes

  Public Partial classStartup { Public voidConfiguration (Iappbuilder app) {Configureauth (APP); }         Public voidConfigureauth (Iappbuilder app) {//Configure The DB context, User Manager and Signin manager to use a single instance per request//app.           Createperowincontext (applicationdbcontext.create); //app.            Createperowincontext<applicationusermanager> (applicationusermanager.create); //app.            Createperowincontext<applicationsigninmanager> (applicationsigninmanager.create); //Enable the application to use a cookie to store information for the signed in user//and to use a cookie to temporarily store information about a user logging in with a third party login provider //Configure the sign in cookieApp. Usecookieauthentication (Newcookieauthenticationoptions {AuthenticationType=Defaultauthenticationtypes.applicationcookie, Loginpath=NewPathString ("/home/index")//,, Cookiesecure=Cookiesecureoption.never//Provider = new Cookieauthenticationprovider//{                //    //enables the application to validate the security stamp when the user logs in. //    //This is a security feature which are used when you change a password or add an external login to your account. //onvalidateidentity = Securitystampvalidator.onvalidateidentity<applicationusermanager, ApplicationUser> (                //validateInterval:TimeSpan.FromMinutes (+),//regenerateidentity: (manager, user) = user. Generateuseridentityasync (manager))//}            }); //app.            Useexternalsignincookie (Defaultauthenticationtypes.externalcookie); //enables the application to temporarily store user information when they is verifying the second factor in the TWO-FA            ctor authentication process. //app.            Usetwofactorsignincookie (Defaultauthenticationtypes.twofactorcookie, Timespan.fromminutes (5)); //enables the application to remember the second login verification factor such as phone or email. //Once You check this option, your second step of verification during the login process would be remembered on the Devic            e where you are logged in from. //This was similar to the rememberme option when you log in. //app.            Usetwofactorrememberbrowsercookie (Defaultauthenticationtypes.twofactorrememberbrowsercookie); //uncomment the following lines to enable logging on with third party login providers//app. Usemicrosoftaccountauthentication (//clientId: "",//Clientsecret: ""); //app. Usetwitterauthentication (//Consumerkey: "",//Consumersecret: ""); //app. Usefacebookauthentication (//appId: "",//Appsecret: ""); //app. Usegoogleauthentication (New Googleoauth2authenticationoptions ()//{            //ClientId = "",//Clientsecret = ""//});        }    }

Login Authentication Code

Claimsidentity ci =Newclaimsidentity (Defaultauthenticationtypes.applicationcookie); Ci. Addclaim (NewClaim (Claimtypes.name,"Brock") ); Ci. Addclaim (NewClaim (Claimtypes.role,"Admin") ); Ci. Addclaim (NewClaim (Claimtypes.email,"[email protected]"));//var id = new Claimsidentity (CI, Defaultauthenticationtypes.applicationcookie, Claimtypes.name, claimtypes.role);varCTX =Httpcontext.getowincontext ();varAuthenticationManager =CTX. Authentication;authenticationmanager.signin (NewAuthenticationproperties () {ispersistent =true}, CI);returnRedirecttoaction ("Test1");//return View ();

ASP. NET MVC claimsidentity Authorization Study (or Beta bug)

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.