How to integrate OpenId with ASP.Net Membership in MVC -


I am using the following code from MVC storefront to test openID in MVC. How can I integrate it with my ASP.NET subscription so that I can save it to my table using the roles for the user? I believe S is also using something similar.

Public Performance OpenIDog () {string returnUrl = VirtualPathUtility.ToAbsolute ("~ /"); Var OpenID = New OpenIDRillingParty (); Var response = openid.GetResponse (); If (feedback == faucet) {// Step 2: Submitting a User Identifier Identifier ID; If (Identifier TryParse (request ["openid_identifier"], ID outside)) {{IAuthenticationRequest req = openid.CreateRequest {request ["openid_identifier"]); Var fetch = new FetchRequest (); // Ask for more information - Email address var item = new AttributeRequest (WellKnownAttributes.Contact.Email); Item.IsRequired = true; Fetch.Attributes.Add (item); Req.AddExtension (fetch); Return Rick Redirectioning Response.ASection Results (); } Catch (before protocol disruption) {View Data ["Message"] = Ex. message; See Return ("Logon"); }} And {visible data ["message"] = "invalid identifier"; See Return ("Logon"); }} And {// Stage 3: Send the OpenID Provider Agency Response Switch (Response Status) {Case Authentication Status. Certified: var fetch = response.GetExtension & lt; FetchResponse & gt; (); String name = response. Friendly IdentifierfreeSpeed; If (fetch! = Null) {IList & lt; String & gt; Email address = fetch Features [WellenAutivant.Command. E-mail]. value; String Email = Email Addresses Account & gt; 0? Email Record [0]: Zero; // Do not show email - it's scary just use the name of the e-mail name = Email. Substring (0, email.IndexOf ('@')); } And {name = name.Substring (0, name.IndexOf ('.')); } //FormsAuthentication.SetAuthCookie (name, wrong); SetCookies (name, name); AuthAndRedirect (name, name); If (! String.IsNullOrEmpty (returnUrl)) {Return Redirect (returnUrl); } And {return redirect action ("index", "home"); } Case authentication status Canceled: View Data ["message"] = "Canceled on Provider"; See Return ("Logon"); Case authentication status.file: seeDATA ["message"] = response. Extension. message; See Return ("Logon"); }} New blank return (); } ActionResult AuthAndRedirect (String Username, String Frankename) {string returnUrl = Request ["Return Url"]; SetCookies (user name, friend name); If (! String.IsNullOrEmpty (returnUrl)) {Redirect Return (returnUrl); } And {return redirect action ("index", "home"); }}

On the stack overflow there are many questions like you that are especially similar.

If you are already using a membership provider for your site and are only adding OpenID, then I think that you are now stuck with membership and one of the answers Can I use a question that I was able to get a semi-decent membership provider, that can work for you.

But if you are writing a new site and you want "Use the roles and save the user's name in my table for the user" as you said, then use ASPNT membership Do not This is not worth it! It does not fit with the password-less pattern of OpenID and causes more sorrow than anything else. If you're a bit afraid of accessing your database, do so. And you can get the behavior of roles very easily by issuing your own FormsAuthentication.RedirectFromLoginPage or

FormsAuthentication.SetAuthCookie and passing in the role of filling the user.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -