User.Identity.Name issues on IIS 7

Hey guys

I am having a very strange issue at the moment. I have a site written in 3.5. It has been hosted for ages on 1 server running IIS 6. Recently, I moved it to a new server running IIS7. The existing code base would not work.

If not logged in, User.Identity.Name was not empty like it used to be, but the User was null until logged in. So I change all the places from:
if (!String.IsNullOrEmpty(User.Identity.Name))


if (User != null && User.Identity != null && !String.IsNullOrEmpty(User.Identity.Name))

Which works fine in the most part. But I have found 2 pages, of all the pages of the site, that it is always null. blog/read.aspx for example. All other pages see the user as logged in. As there is a control on the master page that has login or logout controls depending on your status. But browsing to that page, it is as if the user is always logged off. With Please login to comment message. Browse away, and the user is logged in again. Browse back again and not logged in. It is like that page cannot read the authentication cookie for some reason. And I have no idea why.

FYI. It is Running on a ASP.NET 2.0 Integrated application pool. It does not work on a classic pipeline.

Any ideas?

Thanks for any help

No idea why or what, but I would start by putting in a http module to trace out the value of the User variable at each stage in the pipeline. That can give you a vector on where it gets dumped at least.

Thanks for the suggestion. I will give that a shot. It is a very strange problem. Will post back here if I figure it out


Ok, I figured out that the problem is with the routing. If I browse to the page via a route eg. User is always null. But if I browse to it like this: blogs/read.aspx?id=345 then all works fine.

Any ideas on how to fix this? This is how its setup:


 void RegisterRoutes(RouteCollection routes)
        routes.Add("Blog", new Route("blogs/{blog}", new RouteHandler.BlogsRouteHandler()));

web.confg webserver modules

<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

web.config webserver handlers:

<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>

Route Code:

public class BlogsRouteHandler : IRouteHandler
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
            string blog = requestContext.RouteData.Values["blog"] as string;
            if (String.IsNullOrEmpty(blog))
                return RedirectErrorNotFound();
            HttpContext.Current.Items["blog"] = blog;
            return BuildManager.CreateInstanceFromVirtualPath("~/blogs/read.aspx", typeof(Page)) as Page;

Thanks for any help

I don’t have much to add to the discussion except that I think I had the same issue here:

I think this one also had something to do with it:

Ok, I finally figured it out. The modules tag in the webserver node was missing the attribute: runAllManagedModulesForAllRequests=“true”

As soon as I put that on, everything worked as expected. Stupid oversight on my part, but at least it is sorted, and others could learn from this