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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:06:05+00:00 2026-05-13T17:06:05+00:00

This question is a bit of a structural/design question as I’m having trouble working

  • 0

This question is a bit of a structural/design question as I’m having trouble working out the best way to perform the task.

In my MVC app, I am using DotNetOpenAuth (3.4) as my login information provider and just using the standard FormsAuthentication for cookies etc.

The current user table in the DB has:

  • UserId (PK, uniqueidentifier)
  • OpenIdIdentifier (nvarchar(255))
  • OpenIdDisplay (nvarchar(255))
  • Displayname (nvarchar(50))
  • Email (nvarchar(50))
  • PhoneNumber (nvarchar(50))

As the UserId is the clear identifier for a user (they should be able to change their OpenId provider at a later date), it is the key that other tables link to (for a user).

This is the current code, that on a successfull authentication, creates a temporary user and redirects to Create Action.

        switch (response.Status)
        {
            case AuthenticationStatus.Authenticated:

                FormsAuthentication.SetAuthCookie(response.ClaimedIdentifier, false);

                var users = new UserRepository();
                if (!users.IsOpenIdAssociated(response.ClaimedIdentifier))
                {
                    var newUser = new DueDate.Models.User();
                    newUser.OpenIdIdentifer = response.ClaimedIdentifier;
                    newUser.OpenIdDisplay = response.FriendlyIdentifierForDisplay;

                    TempData["newUser"] = newUser;

                    return this.RedirectToAction("Create");
                }

And now for the crux of the question:

  1. Is the response.ClaimedIdentifier the correct piece of information to be storing against a user?

  2. Is FormAuthentication.SetAuthCookie the preferred way to forms authentication? Or is there a better way?

  3. When I call SetAuthCookie, there is no data relating to the user except for the ClaimedIdentifier. If I’m consistently referring to their UserId, is a better idea to create the user, then store that UserId in the cookie instead of the ClaimedIdentifier?

  4. If I’m using that UserId in a number of places, how do I either retrieve it from the cookie, or store it somewhere else more logical/useful?

A bit long winded but I’ve been having trouble trying to work out the best way to do this/

  • 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-13T17:06:05+00:00Added an answer on May 13, 2026 at 5:06 pm

    1.Is the response.ClaimedIdentifier the correct piece of information to be storing against a user?

    Yes. And make sure the column you store it in the database with is case sensitive. Here is a table schema that demonstrates how to make sure it is case sensitive. This comes out of the DotNetOpenAuth project template’s database schema. The “CS” bit of the specified collation stand for Case Sensitive.

    CREATE TABLE [dbo].[AuthenticationToken] (
        [AuthenticationTokenId]    INT            IDENTITY (1, 1) NOT NULL,
        [UserId]                   INT            NOT NULL,
        [OpenIdClaimedIdentifier]  NVARCHAR (250) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL,
        [OpenIdFriendlyIdentifier] NVARCHAR (250) NULL,
        [CreatedOn]                DATETIME       NOT NULL,
        [LastUsed]                 DATETIME       NOT NULL,
        [UsageCount]               INT            NOT NULL
    );
    

    2.Is FormAuthentication.SetAuthCookie the preferred way to forms authentication? Or is there a better way?

    For MVC apps it definitely is, since you still can return your preferred ActionResult from the method.

    3.When I call SetAuthCookie, there is no data relating to the user except for the ClaimedIdentifier. If I’m consistently referring to their UserId, is a better idea to create the user, then store that UserId in the cookie instead of the ClaimedIdentifier?

    That sounds like personal preference. But I would typically go with user_id, since it might result in a faster database lookup every time an HTTP request comes in that requires you to look up any user information.

    4.If I’m using that UserId in a number of places, how do I either retrieve it from the cookie, or store it somewhere else more logical/useful?

    FormsAuthentication does provide a way to store more information in its encrypted cookie than just username, but it is harder than you’d expect to use it. This snippet comes out of DotNetOpenAuth’s web SSO RP sample:

    const int TimeoutInMinutes = 100; // TODO: look up the right value from the web.config file
    var ticket = new FormsAuthenticationTicket(
        2, // magic number used by FormsAuth
        response.ClaimedIdentifier, // username
        DateTime.Now,
        DateTime.Now.AddMinutes(TimeoutInMinutes),
        false, // "remember me"
        "your extra data goes here");
    
    HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket));
    Response.SetCookie(cookie);
    Response.Redirect(Request.QueryString["ReturnUrl"] ?? FormsAuthentication.DefaultUrl);
    

    Then you can get at that extra data in a future HTTP request with this:

    var cookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
    if (cookie != null) {
        var ticket = FormsAuthentication.Decrypt(cookie.Value);
        if (!string.IsNullOrEmpty(ticket.UserData)) {
            // do something cool with the extra data here
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question is about memory use and objects in actionscript 2. If I have
After having read Ian Boyd 's constructor series questions ( 1 , 2 ,
This is beyond both making sense and my control. That being said here is
I have found this example on StackOverflow: var people = new List<Person> { new
I want to use a temp directory that will be unique to this build.
I have a new web app that is packaged as a WAR as part
(please excuse that I didn't use aliases). I would like my query output to
I'm trying to build a C++ extension for python using swig. I've followed the
Let say I have the following desire, to simplify the IConvertible's to allow me
I have a login.jsp page which contains a login form. Once logged in the

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.