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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:24:29+00:00 2026-06-15T12:24:29+00:00

I wonder if SimpleMembership keeps UserId somewhere, or if not, how to force it

  • 0

I wonder if SimpleMembership keeps UserId somewhere, or if not, how to force it to keep, once derived data.

I have simple action:

    [Authorize(Roles="User")]
    public ActionResult Create()
    {
        var ownerId = WebSecurity.GetUserId(User.Identity.Name);
        return View()
    }

And my MiniProfiler says:

 DECLARE @0 nvarchar(4) = N'NICK'
 SELECT [UserId] FROM [UserProfile] WHERE (UPPER([UserName]) = @0)   

 DECLARE @0 int = 2
 SELECT r.RoleName FROM webpages_UsersInRoles u, webpages_Roles r Where 
 (u.UserId = @0 and u.RoleId = r.RoleId) GROUP BY RoleName 

 DECLARE @0 nvarchar(4) = N'NICK'
 SELECT [UserId] FROM [UserProfile] WHERE (UPPER([UserName]) = @0)  

So, I have duplicated query for UserId – first to get the role, second by calling WebSecurity.GetUserId(User.Identity.Name);. Is there a smart way to save UserId somewhere after calling [Authorize] ?

  • 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-15T12:24:30+00:00Added an answer on June 15, 2026 at 12:24 pm

    I usually wrap my users profiles in a session variable.

     public static userProfile UserInfo
     {
         get { return HttpContext.Current.Session["UserInfo"] as userProfile; }
         set { HttpContext.Current.Session["UserInfo"] = value; }
     }
    

    after the user logins in query the UserProfile table and do

    UserInfo = QueryAsClass; //you need to map your sql to an object
    

    once there you can access it any time by doing

    UserInfo.userId
    

    I have the userProfile table as an object class in my application

    Edit

    I have this code that gets executed after a user logins

    using (var db = new DBEntities())
        {
            var userId = WebSecurity.GetUserId(HttpContext.Current.User.Identity.Name);
            if (userId == -1) return;
            SessionHelpers.UserInfo = db.userProfiles.Single(x => x.userId == userId);
        }
    

    I’m using EF5 and I have the userProfile table in my model, so you’ll need to adapt this part if you’re not using EF.

    When I need the userId I just do SessionHelpers.UserInfo.userId. This let’s me get all of the users profile info whenever I need it without requerying the database.

    Of course if you change something in the user’s profile you will need to update your session variable as well.

    You may need to have more advanced logic and check that the session isn’t null (which I’m doing elsewhere).

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

Sidebar

Related Questions

wonder whether someone can help me with the following one... I have a struct
wonder if someone could help me with a little problem. I have session values
I wonder, using Eclipse's PyDev plugin , how come documentation does not always show
I wonder, why do I get not full response from my server ( Win
Wonder if someone could give me a quick hand. I have 2 select queries
wonder if anyone can help; I have an a two dimensional array which I
Wonder if there is a js plugin to control music volume? I have all
I wonder if it's possible to have a folder such as res/values-small or res/values-hdpi
I wonder how Object Oriented data modeling is different from Object Relational data modeling?
I wonder if in my program I have only 1 thread, can I write

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.