Form Authenticationテストで使用していました。また、テスト用のユーザー名もいくつかありますが、指定された名前に奇妙な問題が見つかりました。これは、名前付きの 1 つだけがテストで機能することを除いて、すべてのテスト名amybeyondです。
テストでコードを確認するのを手伝ってください。
LoginTest.aspx (ユーザー名とパスワードを入力するためのログインフォームです。)
public partial class LoginTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//after succeed validating user. then redirect to LoginSuccess.aspx page.
bool bValidate=Membership.ValidateUser("amybeyond", "11111111");
if (bValidate)
{
FormsAuthentication.SetAuthCookie("AmyBeyond", false);
Response.Redirect("LoginSuccess.aspx");
}
}
}
LoginSuccess.aspx (このページでは、リダイレクト後に現在の要求が認証されているかどうかをテストするだけです。)
public partial class LoginSuccess : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//the HttpContext.Current.Request.IsAuthenticated always false in the IE.
if (HttpContext.Current.Request.IsAuthenticated)
{
Response.Write("ok, you login successfully.");
}
}
}
Membership.ValidateUserが正常に実行され、return true. 問題は、リダイレクトに成功した後、認証されたステータスを認識できないことです。
何かを見逃したのか、何か間違ったことをしたのかわかりませんでした。もしあるなら 。教えてください。ありがとうございます。
追加した
のソースコードを読みましたFormsAuthentication.SetAuthCookie。cookieless="UseCookies"のForms要素にを追加しWeb.configます。Cookie が に追加されていることを確認してくださいResponse(これはソース コードによって行われますHttpContext.Current.Response.Cookies.Add(cookie))。それでもうまくいきません。
public static void SetAuthCookie(string userName, bool createPersistentCookie, string strCookiePath)
{
Initialize();
HttpContext current = HttpContext.Current;
if (!current.Request.IsSecureConnection && RequireSSL)
{
throw new HttpException(SR.GetString("Connection_not_secure_creating_secure_cookie"));
}
bool flag = CookielessHelperClass.UseCookieless(current, false, CookieMode);
HttpCookie cookie = GetAuthCookie(userName, createPersistentCookie, flag ? "/" : strCookiePath, !flag);
if (!flag)
{
HttpContext.Current.Response.Cookies.Add(cookie);
current.CookielessHelper.SetCookieValue('F', null);
}
else
{
current.CookielessHelper.SetCookieValue('F', cookie.Value);
}
}
追加した
http キャプチャの詳細を以下に示します。には、この Cookieへのリダイレクトが失われた後、LoginTest.aspxという名前のCookie があります。レビューにご協力ください。FwLoginCookieLoginSuccess.aspx


