SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,868
    Mentioned
    37 Post(s)
    Tagged
    0 Thread(s)

    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 asp.net 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))

    to

    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

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,576
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,868
    Mentioned
    37 Post(s)
    Tagged
    0 Thread(s)
    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

  4. #4
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,868
    Mentioned
    37 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Ok, I figured out that the problem is with the routing. If I browse to the page via a route eg. site.com/blogs/blog-title. 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:

    Global
    Code:
     void RegisterRoutes(RouteCollection routes)
        {
            routes.Add("Blog", new Route("blogs/{blog}", new RouteHandler.BlogsRouteHandler()));
    }
    web.confg webserver modules
    Code:
    <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    web.config webserver handlers:
    Code:
    <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    Route Code:
    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

  5. #5
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I don't have much to add to the discussion except that I think I had the same issue here:
    http://www.sitepoint.com/forums/show...rous-headaches.

    I think this one also had something to do with it:
    http://www.sitepoint.com/forums/show...mbership-Users

  6. #6
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,868
    Mentioned
    37 Post(s)
    Tagged
    0 Thread(s)
    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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •