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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:54:02+00:00 2026-06-18T12:54:02+00:00

I have a basic Authentication system on my Asp.net MVC Website [HttpPost] public ActionResult

  • 0

I have a basic Authentication system on my Asp.net MVC Website

[HttpPost]
public ActionResult Login(LoginViewModel model, string returnUrl)
{
    WebSecurity.Login(model.UserName, model.Password, persistCookie: false)

    return RedirectToAction("Index", "Home");
}

I also have a UserInfoViewModel class where i keep some user specific information, and i use it on different pages.

To avoid creating the UserInfoViewModel every time i need it, i want to save it in Session on Login method.

public ActionResult Login(LoginViewModel model, string returnUrl)
{
   WebSecurity.Login(model.UserName, model.Password, persistCookie: false)
   var userInfoViewModel = new UserInfoViewModel();
   Session["userInfo"] = userInfoViewModel;

    return RedirectToLocal(returnUrl);
}

Considering that i have sensitive information that i rely on inside UserInfoViewModel, like IsSuperuser, is it safe to keep that object in Session? Will it expire when the user login session expires as well?

SOLUTION

System.Security.Principal.IIdentity is exacly made for that. It saves inside AUTH cookie custom user information you need, so you don’t recalculate it every time.

Use Custom Principal Objects video turorial

Thank you for answers!

  • 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-18T12:54:04+00:00Added an answer on June 18, 2026 at 12:54 pm

    Yes, it is safe because the Session is stored on the server. But you have another problem you should be thinking about if you decide to use ASP.NET Sessions. If this session is stored in the memory of the web server (default), IIS could recycle your application at any time and you will loose this session data. On the other hand the user will still be authenticated because he is tracked by a forms authentication cookie which will still be sent. So if you want to use Sessions I would recommend you switching to an out-of-proc session provider (such as StateServer or SQLServer).

    Also as @Mikeb is pointing out in the comments section there’s another very serious issue with the Session. If you enabled it for read and write mode for a given controller you will not be able to process multiple requests from the same session in parallel. The server will block and process them sequentially. Think for example multiple AJAX requests from the same session. They will all block and process sequentially.

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

Sidebar

Related Questions

I have a website that uses basic ASP.Net forms authentication. In the web.config file
We have started building an asp.net mvc application. Application will consist with one main
This is not an MVC topic. I have an ASP.NET Application which performs URL
I have been trying to write an basic authentication system as part of a
I have a node.js Express application with a basic user authentication system where the
I am implementing a basic authentication WCF service in ASP.NET using Visual Studio 2010.
I have a WSS installation that's behind basic authentication/SSL (it's hosted at a public
I have a basic authentication system just like in Michael Hartl's Ruby on Rails
I have a WCF web service, and I want to use Basic authentication. I
In IIS 5.1, i have set the website security to Basic Authentications and i

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.