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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:25:02+00:00 2026-06-12T16:25:02+00:00

I currently have the following login script: [HttpPost] public ActionResult LogOn(LogOnModel model) { if

  • 0

I currently have the following login script:

[HttpPost]
        public ActionResult LogOn(LogOnModel model)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    Guid MyUserId = (Guid)Membership.GetUser().ProviderUserKey;
                    System.Web.HttpContext.Current.Session[MyUserId.ToString()] = profileRepository.GetFullProfile(MyUserId);
                    return Json(true);                  
                }
                else
                {
                    return Json("The user name or password provided is incorrect.");
                }
            }else
                return Json("The user name or password provided is incorrect.");

        }

I get an error on the Membership.GetUser() saying the object reference error. I researched this and i found it was because only my next http request will be authenticated, so what is the best way to save a user’s data into session when the user logins? will it be assured to be in the session until the user’s session expires and kicks him out or will there ever be an instance where the user is logged in without the session data set? If so ill need something to handle that as well.

  • 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-12T16:25:03+00:00Added an answer on June 12, 2026 at 4:25 pm

    This has happened to me in LoginButton_Clicked in an asp.net application (Not MVC). Even thought this event (LoginButton_Clicked) fires after a successful login Membership.GetUser(), Roles.GetRolesForUser(), Profile Are yet filled in. Therefore username needs to be passed into each method to get the details.

    I think same thing happening in MVC as well.

    You can get the user details by passing model.UserName as follows.

    MembershipUser mu = Membership.GetUser(model.UserName);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have the following code. Basically, just a login page and a modal
I currently have the following in one solution: Core Project (data access, biz logic,
I have the following rule in my current .htaccess file to redirect /videos/login/ requests
Currently I have following XML: <Rowsets> <Rowset> <Row> <DrilldownDepth>0</DrilldownDepth> <ScheduleWeek>---</ScheduleWeek> <ABC>---</ABC> <PQR>1500</PQR> <XYZ>15000</XYZ> <Quant>285</Quant>
I currently have the following controller method in a Rails app: def index @entries
I currently have the following SQL query that lists all the names of all
I currently have the following Get-ChildItem -recurse -include file.ext | Select-String -pattern c: |
I currently have the following htaccess rewrite rule: RewriteRule (.*) index.php/$1 [L] How do
I currently have the following CSS (called splash.css): html { background:url(splash.jpg) center no-repeat; background-size:auto
I currently have the following code which delays showing a fixed bar after a

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.