0

I am building a non-mvc website using C# and ASP.NET 3.5. I have custom routes working well, and have done the same on other sites. I also have forms authentication working well and have used forms authentication on other sites, but never both at the same time.

On this site http://ec2-23-20-231-127.compute-1.amazonaws.com/ I can login (user/pass = demo/demo) and have a user context as long as I am on a page which contains .aspx. For example if I go to www.mysite.com/default.aspx I have a user context.

To test this : Request.IsAuthenticated returns true and `System.Web.HttpContext.Current.User.Identity.IsAuthenticated* also returns true.

But if I go to www.mysite.com/ I have no user context : Request.IsAuthenticated returns false and System.Web.HttpContext.Current.User.Identity.IsAuthenticated returns "Object not set to instance of an object".

I have also confirmed that the cookie is being set and can view it using Firefox.

My routes are setup as follows (in Global.asax):

void Application_Start(object sender, EventArgs e) 
{
    // Code that runs on application startup
    RegisterRoutes(System.Web.Routing.RouteTable.Routes);
}

public static void RegisterRoutes(RouteCollection routes)
{
    routes.Add("Default", new Route("", new Brandpoint.DefaultRouteHandler()));
    routes.Add("Category", new Route("{catTitle}/", new Brandpoint.CategoryRouteHandler()));
    routes.Add("Article", new Route("{catTitle}/{articleTitle},{articleId}", new Brandpoint.ArticleRouteHandler()));
} 

Forms Authentication is setup as follows:

<authentication mode="Forms">
    <forms name="BrandpointContent" path="/" loginUrl="Login.aspx" protection="All" timeout="5000000"></forms>
</authentication>
<authorization>
    <deny users="?"/>
</authorization>

Setting the cookie is simply:

FormsAuthentication.SetAuthCookie("USERS-ID-HERE", true);

I'm fairly well versed in both routes and forms auth, but this has me stumped.

Anyone know how to make it work?

Mickäel A.
  • 9,012
  • 5
  • 54
  • 71
jleger
  • 1
  • 1
  • Of course as soon as I posted this I found the answer in a suggested post (which i could not find by searching) The answer was found here: http://stackoverflow.com/questions/1534162/iroutehandler-in-web-forms-routing-requests-that-require-httpcontext-user?rq=1 in your web.config->system.webServer->modules you have to add runAllManagedModulesForAllRequests="true" So change this: to this: This solved my issue. Hopefully this will help someone else as well. – jleger Mar 04 '14 at 16:05
  • can you send us the web.config? lol yeah figured as much :) – Liran Mar 04 '14 at 16:05

0 Answers0