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

  • Home
  • SEARCH
  • 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 9169611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:54:11+00:00 2026-06-17T15:54:11+00:00

I am trying to setup a .NET MVC 3 project to store a custom

  • 0

I am trying to setup a .NET MVC 3 project to store a custom user session object (which can then be later accessed from a Custom Principal object on other subsequent actions)
I have followed the steps here:
ASP.NET MVC – Set custom IIdentity or IPrincipal
(What LukeP says – i needed the custom membership etc too)

On my login action, I have something like this:


if (provider.ValidateUser(model.UserName, model.Password))
{
        // setup principal 
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        string userData = serializer.Serialize(provider.GetSession());

        FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
             1,
             model.UserName,
             DateTime.Now,
             DateTime.Now.AddMinutes(15),
             false,
            userData);

        string encTicket = FormsAuthentication.Encrypt(authTicket);
        HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
        Response.Cookies.Add(faCookie);

        if (!String.IsNullOrEmpty(returnUrl))
        {
            return Redirect(returnUrl);
        }
        else
        {
            return RedirectToAction("Index", "Home");
        }
}
else
{
    ModelState.AddModelError("", "The user name or password provided is incorrect.");
}

Which will basically get the user object (provider.GetSession() returns a custom user session object from an external auth service) and then store it in the FormsAuthenticationTicket

Problem is that the User session object from the external service is over 4Kb (its about 7Kb encrypted), and what’s happening is that the cookie isn’t getting stored in the browser because of the size.

Is there any other safe way to store this user session object somewhere, so i dont have to keep querying the database for it?
I have heard that storing it in a Session is unsafe (because of session hijacking – and it being decoupled from membership.) – so what other choice do i have?

I cant reduce the size of the custom user session object – this isnt an option due to its properties being reliant on all system layer calls.

regards,
martin

  • 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-17T15:54:12+00:00Added an answer on June 17, 2026 at 3:54 pm

    I don’t see why you couldn’t store it in the user’s session object since you should be validating their forms authentication each time they do something privileged.

    If you really don’t want to store it in their session, you could create a static dictionary and store the data there:

    using System.Collections.Concurrent;
    
    // Class level declaration.
    static ConcurrentDictionary<string, object> UserData =
            new ConcurrentDictionary<string, object>();
    
    // Inside your magic method.
    if (provider.ValidateUser(...)) {
      object providerSession = provider.GetSession();
      string userId = Guid.NewGuid().ToString("n");
    
      UserData.TryAdd(userId, providerSession);
    
      FormsAuthenticatonTicket authTicket = new FormsAuthenticatonTicket(
        1,
        model.UserName,
        DateTime.Now,
        DateTime.Now.AddMinutes(15),
        false,
        userid);
    
      // ...
    }
    

    From there, you could then look up your providers session data based on the stored userId in your forms authentication ticket. I made the object stored in the dictionary a standard object since I don’t know what your provider returns, so if it’s something more specific, be sure to use that class instead.

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

Sidebar

Related Questions

I'm trying to setup xVal with an ASP.NET MVC 2 Preview 1 project. I'm
Im trying to setup my asp.net mvc page like the following image: The header
I'm trying to setup configSection for a .net 4.0 project. <configuration> <configSections> <section name=MonitorFldrSection
I'm trying to setup Forms Authentication in an asp.net mvc 2 application that will
I have an ASP.NET MVC 4 app. I'm trying to setup my routes in
I'm trying to get setup using the DataAnnotations validator in ASP.Net MVC 2.0 Beta,
I'm trying to get an MVVM setup going for a ASP.NET MVC 4 application
I'm trying to setup an Area Route in my ASP.NET MVC application. I'm also
I am trying to implement CKFinder in my MVC.Net website, but the default setup
I'm trying to implement a small ASP.NET MVC site which interacts with another site.

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.