Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7093509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:26:53+00:00 2026-05-28T08:26:53+00:00

I am building an application in ASP.NET MVC 3 in which I have implemented

  • 0

I am building an application in ASP.NET MVC 3 in which I have implemented Forms authentication.

I would also like to give the user the option to Sign-up/log-in with their facebook account(and possibly other social accounts in the future.)

I am using the C# Facebook SDK

I have successfully implemented the facebook login workflow. Now my question is, how to handle mixing both Forms and Facebook Auth? I can’t seem to find any sufficient examples of how to accomplish this.

In regards to my facebook implementation, I am requesting permission from the user for a non-expiring Auth Token which I will store in my database.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:26:54+00:00Added an answer on May 28, 2026 at 8:26 am

    For this you will have to do something like this

    1. Create a custom class (CurrentIdentity) which implements IIdentity. Override .ToString() for this class, and so that you have some sort of serialized state of object. I had use “|” seperator. This string will be stored in encrypted cookie.
    2. Create a session cookie

      public static HttpCookie AuthCookie(CurrentIdentity identity) {
         //Create the Authticket, store it in Cookie and redirect user back
         FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1,
                            identity.Name, DateTime.Now, DateTime.Now.AddHours(3), true, identity.ToString(), FormsAuthentication.FormsCookiePath);
         string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
         HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
         authCookie.Expires = authTicket.Expiration;
         return authCookie;
      }
      
    3. Add this cookie to response.

      HttpResponse res = HttpContext.Current.Response;
      res.Cookies.Add(Helper.AuthCookie(identity));
      res.Redirect(FormsAuthentication.GetRedirectUrl(identity.Name, true));
      res.End();
      
    4. Now in Gloabl.asax, inside *Application_AuthenticateRequest* read this cookie and populate your CurrentIdentity object, something like this.

      if (Request.IsAuthenticated == true) {
              // Extract the forms authentication cookie
              string cookieName = FormsAuthentication.FormsCookieName;
              HttpCookie authCookie = Context.Request.Cookies[cookieName];
      
              if (null == authCookie) {
                  // There is no authentication cookie.
                  return;
              }
              FormsAuthenticationTicket authTicket = null;
              try {
                  authTicket = FormsAuthentication.Decrypt(authCookie.Value);
              } catch (Exception) {
                  // Log exception details (omitted for simplicity)
                  return;
              }
      
              if (null == authTicket) {
                  // Cookie failed to decrypt.
                  return;
              }
              // When the ticket was created, the UserData property was assigned a
              // pipe delimited string of role names.
              string[] userInfo = authTicket.UserData.Split('|');
      
              // Create an Identity object
              FormsIdentity id = new FormsIdentity(authTicket);
              //Populate CurrentIdentity, from Serialized string
              CurrentIdentity currentIdentity = new CurrentIdentity(userInfo[0], userInfo[1], userInfo[2]);
              System.Security.Principal.GenericPrincipal principal = new System.Security.Principal.GenericPrincipal(currentIdentity, userInfo);
              Context.User = principal;
      }
      

    This should solve your problem. I have implemented similar thing on my company’s website.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building an asp.net mvc application. I have my top menu structure which
I 'm building an application in ASP.NET MVC which should use Gmail authentication and
I have an ASP.NET MVC application I'm building and I'm using a Master page.
We have started building an asp.net mvc application. Application will consist with one main
We are building an ASP.NET MVC application which will be deployed behind a hardware
I'm building an application which (currently) consists of one web application (ASP.NET MVC) and
I have ASP.NET MVC web application. I need to deploy it which consists of:
I'm building ASP.Net MVC application kinda Game which deal a lot with online users
I am building an ASP.NET MVC 3 application, where I have on list of
I am building a web application using ASP.NET MVC that has two very distinct

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.