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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:23:43+00:00 2026-06-06T04:23:43+00:00

I am currently developing a site using ASP.NET MVC 3, I am using Nhibernate.

  • 0

I am currently developing a site using ASP.NET MVC 3, I am using Nhibernate. I created a custom MembershipProvider as described below.

My question is time to record the user authentication in a session in ValidateUser method and retrieves it in GetUser.

From what I noticed you can not use Session in the ValidateUser, but it is not correct to use Cache, since the storage is not per user session.

How do I do?

class MyMembershipProvider : MembershipProvider
{
    public override MembershipUser GetUser(string username, bool userIsOnline)
    {
        var membershipUser = MyMembershipUser)HttpContext.Current.Cache.Get(username);

        // Is not possible
        // var membershipUser = (MyMembershipUser) HttpContext.Current.Session[username];

        return membershipUser;
    }

    public override bool ValidateUser(string username, string password)
    {
        var usuario = UsuarioRepository.GetUsuarioAuthentication(username, password);

        if (usuario != null)
        {
            HttpContext.Current.Cache.Add(username, new MyMembershipUser(usuario.Id, usuario.Email), null,
                                          Cache.NoAbsoluteExpiration, FormsAuthentication.Timeout,
                                          CacheItemPriority.Default, null);

            // Is not possible 
            // HttpContext.Current.Session.Add(username, new MyMembershipUser(usuario.Id, usuario.Email));

            return true;
        }

        return false;
    }

}

  • 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-06T04:23:45+00:00Added an answer on June 6, 2026 at 4:23 am

    Session is not involved at all when you use ASP.NET Membership with Forms Authentication.

    Once the user has successfully authenticated, simply call

    FormsAuthentication.SetAuthCookie() 
    

    and an authenication cookie is automatically created for you. Don’t call this in ValidateUser(), but rather from the client code that calls ValidateUser().

    The authentication cookie is completely independent of the session cookie.

    Refer Forms Authentication on MSDN for more info.

    If you want to cache your authenticated user’s user details, again this should be done in the client code that calls Membership.ValidateUser(), not in the membership provider itself. The membership provider GetUser() and ValidateUser() should do as their names suggest, and not have any other side effects.

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

Sidebar

Related Questions

I am currently developing an ASP.NET MVC 3 site using Visual Studio 2010 with
I'm currently developing a site using ASP.Net MVC3 with Razor. Inside the View/Shared folder,
I am currently developing an events calendar application using ASP.NET MVC and SQL Server
I am currently developing a web site using ASP.NET 3.5. On a page there
I'm currently developing an image viewer using asp.net MVC. The image viewer itself works
I am developing an application using ASP.NET MVC 1 and VS2008. When I deploy
Using ASP.Net Am New to website development Currently am developing a web pages, when
I'm currently developing a site in ASP.NET Webforms.. I'm caching things where it makes
I'm developing a website in ASP .NET MVC 2 using C#. I have a
I am currently developing GA reporting web app for my company using asp.net Google

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.