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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:30:19+00:00 2026-05-21T11:30:19+00:00

What is the recommended solution for keeping track of the current user in a

  • 0

What is the recommended solution for keeping track of the current user in a site using OpenId? Say I have a Users table with an id and a claimed identifier and then my site specific info and the user wants to update their site specific info. What is the best way to track the current user given that I am not using the built in membership? Should I send a request to openid to get the ClaimedIdentifier each time a user attempts to update their profile? Or perhaps just enforce a UserName be unique and get the user’s info based off of User.Identity.Name?

  • 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-21T11:30:19+00:00Added an answer on May 21, 2026 at 11:30 am

    I do it with a cookie :)… you might find my answer useful: What OpenID solution is really used by Stack Overflow?

    I’ve also made a simple blog post about it: http://codesprout.blogspot.com/2011/03/using-dotnetopenauth-to-create-simple.html

    public class User
    {
        [DisplayName("User ID")]
        public int UserID{ get; set; }
    
        [Required]
        [DisplayName("Open ID")]
        public string OpenID { get; set; }
    
        [DisplayName("User Name")]
        public string UserName{ get; set; }
    }
    

    In my example I signed in with the OpenID and I stored it in the cookie, but you can store other information in the cookie, such as the user name:

    public class FormsAuthenticationService : IFormsAuthenticationService
    {
        public void SignIn(string userName, bool createPersistentCookie)
        {
            if (String.IsNullOrEmpty(serName)) throw new ArgumentException("The user name cannot be null or empty.", "UserName");
    
            FormsAuthentication.SetAuthCookie(userName, createPersistentCookie);
        }
    
        public void SignOut()
        {
            FormsAuthentication.SignOut();
        }
    }  
    

    Update 2.0:
    How about something like this (this is the View):

    <%
        if (Request.IsAuthenticated) 
        {
            string name = Request.Cookies[Page.User.Identity.Name] == null ? string.Empty : Request.Cookies[Page.User.Identity.Name].Value;
            if (string.IsNullOrEmpty(name))
            {
                name = Page.User.Identity.Name;
            }
    %>
    
            [<%: Html.ActionLink(name, "Profile", "User")%> |
             <%: Html.ActionLink("Log out", "LogOut", "User") %> |
    <%
        }
        else 
        {
    %> 
            [ <%: Html.ActionLink("Log in", "LogIn", "User") %> |
    <%
        }
    
    %>
    

    And the Controller, presumably you’re taken to a Profile page after you log in (or you could set the Response.Cookies in the LogIn method) and when you’re loading up the model you set the display name in the cookie:

        [Authorize]
        [HttpGet]
        public ActionResult Profile(User model)
        {
            if (User.Identity.IsAuthenticated)
            {
                userRepository.Refresh();
                model = userRepository.FetchByOpenID(User.Identity.Name);
    
                // If the user wasn't located in the database
                // then add the user to our database of users
                if (model == null)
                {
                    model = RegisterNewUser(User.Identity.Name);
                }
    
                Response.Cookies[model.OpenID].Value = model.DisplayName;
                Response.Cookies[model.OpenID].Expires = DateTime.Now.AddDays(5);
    
                return View(model);
            }
            else
            {
                return RedirectToAction("LogIn");
            }
        }
    

    You can see it all in action on a little project I have: mydevarmy. I’m going to post a user profile soon and you will be able to change the display name (which is automatically generated for now).

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

Sidebar

Related Questions

Possible Duplicate: Java: recommended solution for deep cloning/copying an instance I have an object
The recommended solution is this: config.active_record.whitelist_attributes = true But this only works if you
Can someone recommend a hosted solution that answers the following requirements (I have seen
I have been recommended to put a space between foreach and (, among other
Using SqlParameters is a recommended method to prevent SQL Injection in your database queries.
After learning how to do MySQL Full-Text search, the recommended solution for multiple tables
I am using a search library which advises keeping search handle object open for
I have cascading drop down lists in a .net mvc view and am using
We have some client code which is using the SqlConnection class in .NET to
What's the recommended solution to build a ruby on rails app that streams audio/video

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.