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 7742249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:13:52+00:00 2026-06-01T09:13:52+00:00

Im trying to make my own FormsAuthentication in an ASP.NET MVC 4 application and

  • 0

Im trying to make my own FormsAuthentication in an ASP.NET MVC 4 application and I have seen two different ways of creating my authcookie and I was wondering if one of them is having any disadvantages or if it is safe to use them both and are there any other differences I should know about before I decide witch to use?

the first one is

FormsAuthentication.SetAuthCookie(userName, rememberMe);

the other one is a bit longer

            var authTicket = new FormsAuthenticationTicket(
            1,
            userName,
            DateTime.Now,
            DateTime.Now.AddMinutes(30),
            rememberMe,
            "Users"
            );
        var encryptedTicket = FormsAuthentication.Encrypt(authTicket);

        var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
        HttpContext.Current.Response.Cookies.Add(authCookie);

please enlighten me about this decision

  • 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-06-01T09:13:53+00:00Added an answer on June 1, 2026 at 9:13 am

    Actually, the first method calls the second method. I have taken the source of the SetAuthCookie to show this, but removed some lines to keep it relevant:

    public static void SetAuthCookie(string userName, bool createPersistentCookie)
    {
        FormsAuthentication.Initialize();
        FormsAuthentication.SetAuthCookie(userName, createPersistentCookie, FormsAuthentication.FormsCookiePath);
    }
    
    public static void SetAuthCookie(string userName, bool createPersistentCookie, string strCookiePath)
    {
        (...)
        HttpCookie authCookie = FormsAuthentication.GetAuthCookie(userName, createPersistentCookie, flag ? "/" : strCookiePath, !flag);
        (...)
        HttpContext.Current.Response.Cookies.Add(authCookie);
        (...)
    }
    
    private static HttpCookie GetAuthCookie(string userName, bool createPersistentCookie, string strCookiePath, bool hexEncodedTicket)
    {
        (...)
        DateTime utcNow = DateTime.UtcNow;
        DateTime expirationUtc = utcNow.AddMinutes((double) FormsAuthentication._Timeout);
        FormsAuthenticationTicket ticket = FormsAuthenticationTicket.FromUtc(2, userName, utcNow, expirationUtc, createPersistentCookie, string.Empty, strCookiePath);
        string str = FormsAuthentication.Encrypt(ticket, hexEncodedTicket);
        (...)
        HttpCookie httpCookie = new HttpCookie(FormsAuthentication.FormsCookieName, str);
        (...)
        return httpCookie;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to make my own ExceptionFilter. Out of the box, ASP.NET MVC comes
I am trying to make my own user control and have almost finished it,
I am trying to make my own Jabber bot but i have run into
I'm trying to make my own control in for .NET using VB and I'm
I've been trying to make my own plugin system. I have 2 separate projects.
im trying to make my own chat... so i have an input text field,
I'm trying to make my own application that will listen to the media-keys in
I am trying to make my own confirm dialogs with two parameters. function myAlert(message,
I was trying to make my own class for currencies using longs, but apparently
I've been trying to make my own basic .obj (Wavefront) renderer using the OpenGL

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.