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
Bookmarks