C#とASP.NET 3.5を使用して非 mvc Web サイトを構築しています。カスタムルートがうまく機能しており、他のサイトでも同じことをしています。また、フォーム認証がうまく機能しており、他のサイトでフォーム認証を使用したことがありますが、両方を同時に使用することはありません.
このサイトhttp://ec2-23-20-231-127.compute-1.amazonaws.com/でログインでき (user/pass = demo/demo)、ページにいる限りユーザー コンテキストを使用できます。 .aspx が含まれています。たとえばwww.mysite.com/default.aspx
、ユーザー コンテキストがあるとします。
これをテストするには: trueRequest.IsAuthenticated
を返し、`System.Web.HttpContext.Current.User.Identity.IsAuthenticated* もtrueを返します。
しかし、私が行くとwww.mysite.com/
、ユーザーコンテキストがありません: falseをRequest.IsAuthenticated
返し、 を返します。System.Web.HttpContext.Current.User.Identity.IsAuthenticated
"Object not set to instance of an object"
Cookieが設定されていることも確認しており、Firefoxで閲覧できます。
私のルートは次のように設定されています(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()));
}
フォーム認証は次のように設定されます。
<authentication mode="Forms">
<forms name="BrandpointContent" path="/" loginUrl="Login.aspx" protection="All" timeout="5000000"></forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
Cookie の設定は簡単です。
FormsAuthentication.SetAuthCookie("USERS-ID-HERE", true);
私はルートとフォーム認証の両方にかなり精通していますが、これには困惑しています。
誰でもそれを機能させる方法を知っていますか?