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?