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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:28:02+00:00 2026-06-01T20:28:02+00:00

I am pretty new to MVC and am having difficulties getting my application to

  • 0

I am pretty new to MVC and am having difficulties getting my application to run on my staging webserver. On my local machine and dev server it is running fine.

The issue is that in my Action the User is null (on staging, not on dev and local). I googled reasons why the User would be null, but everything seems covered. Strange thing is that it works perfectly on 2 servers.

Here is my code…

In Global.asax
Using PostAcquireRequestState I override the principal using a custom principal holding an object stored in Session. Hence the SessionHelper which will get the object and add it to the principal. The principal is then set to the httpcontext and thread.

public class MvcApplication : HttpApplication
{
    public MvcApplication()
    {
        PostAcquireRequestState += new EventHandler(MvcApplication_PostAcquireRequestState);
    }

    void MvcApplication_PostAcquireRequestState(object sender, EventArgs e)
    {
        if (Context.User is ICSPrincipal)
            return;

        var principal = new ICSPrincipal(new GenericIdentity(User.Identity.Name), SessionHelper.UserClaims);
        HttpContext.Current.User = principal;
        Thread.CurrentPrincipal = principal;
    }

    ...
}

In my controller I will retrieve the value stored in the principal.
But the problem is that User is null on my staging server.
It works however on my local machine and my development server.
Development server and staging server are running the same version of IIS and both have MVC3 installed.

public class HomeController : Controller
{
   public ActionResult Index()
   {
        //PROBLEM!!! User is NULL on staging server.
        var userClaims = ((ICSPrincipal)User).UserClaims;
        ...
   }
}

Does anyone have any experience with this problem and got it solved? I was under the impression I could safely call User from within my Action.

EDIT: Situation sketch on why I require SessionStorage in combination with a custom principal.

I use formsauthentication so the authentication is covered. However I used to store an object which held extra userdata (firstname, lastname; 6 properties in total) into the userdata from the authentication cookie.
However investigating my requests I saw that each request (even for images; and I know I can optimize this using a cookieless domain, but that’s a next step) was over 2.5KB. Therefor I switched back to just storing username in the cookie and on each request I want the data to be completed from session storage.
That’s why I thought a custom principal would be great. It starts with a generic principal and once we get to the Action there is a custom principal with all the data I require coming from wherever I want (in this case username from cookie added with data from session).

I hear you say: but hey, using Session is not safe, it expires after a while. And I am well aware of this, that’s why SessionHelper has ofcourse some intelligence. If the Session object is null, it will get all data required based on the authenticated user’s username. It than stores this data in Session so subsequent requests don’t query my database.

I also use API communication (http or named pipes) and that’s why I need this data in the custom principal. I can’t access Session from that layer, but I can access the principal. Therefor if the principal is updated before getting to that communication everything works fine.

GETTING TO THE ACTUAL PROBLEM:

This setup described above actually works fine on multiple machines, but not on my staging server which is the same setup as my development server.
Staging complaints that User is null in my action. And I don’t know how that’s even possible.

  • 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-01T20:28:04+00:00Added an answer on June 1, 2026 at 8:28 pm

    http://support.microsoft.com/kb/980368/en

    After this patch is applied, ASP.NET 4 applications can handle requests for extensionless URLs. Therefore, managed HttpModules that run prior to handler execution will run. In some cases, the HttpModules can return errors for extensionless URLs. For example, an HttpModule that was written to expect only .aspx requests may now return errors when it tries to access the HttpContext.Session property.

    This has fixed the issue! Thanks all for making me experiment with multiple settings. This way I came up with this solution.

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

Sidebar

Related Questions

I'm pretty new to MVC 2 and I'm having problems figuring out how to
I'm pretty new to MVC, ASP.net, and, well, server-side scripting in general. I was
Pretty new to MVC and the like. I have a class the looks like
I'm pretty new to ASP.NET MVC and I hope it is not a too
I am pretty new to database design. I am building a small asp.net mvc
New to MVC, so hopefully this will be pretty simple. I have an HTML
I'm trying to deploy my new ASP.NET MVC 2.0 website to our Windows Server
I'm pretty new to MVC 2 using the Entity Framework. I have two tables
i am pretty new to MVC and Routing and i was asked to modify
I'm pretty new in the ASP .NET MVC world. Maybe, that's the reason 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.