我決定重新寫了一個問題,我發現瞭如何實現上述的一些信息: http://msdn.microsoft.com/en-us/library/aa289495%28v=vs.71%29.aspx如何檢查,如果瀏覽器在Web應用程序中啓用Cookie?
不過,我的問題是,我試圖做的一切,在Page_Load
事件的Login.aspx.cs
。
最初它似乎工作正常,直到我試圖通過輸入我的憑據和單擊登錄按鈕實際登錄。然後所有的地獄破壞,我得到一個無盡的循環。它始終在Login.aspx.cs
和TestForCookies.aspx.cs
之間的Page_Loads之間來回切換。 。每次重定向URL增長由另一"?AcceptCookies=1
」有一個變通這個
Login.aspx.cs代碼:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Request.QueryString["AcceptsCookies"] == null)
{
Response.Cookies["TestCookie"].Value = "ok";
Response.Cookies["TestCookie"].Expires = DateTime.Now.AddMinutes(1);
Response.Redirect(BasePage.ResolveUrl("~/Common/TestForCookies.aspx?redirect=" + Server.UrlEncode(Request.Url.ToString())));
}
else
{
LoginBox.InstructionText = "Accept cookies = " + Request.QueryString["AcceptsCookies"];
}
}
}
TestForCookies.aspx.cs代碼:
protected void Page_Load(object sender, EventArgs e)
{
string redirect = Request.QueryString["redirect"];
string acceptsCookies = null;
// Was the cookie accepted?
if (Request.Cookies["TestCookie"] == null)
{
// No cookie, so it must not have been accepted
acceptsCookies = "0";
}
else
{
acceptsCookies = "1";
// Delete test cookie
Response.Cookies["TestCookie"].Expires = DateTime.Now.AddDays(-1);
}
string url = redirect + "?AcceptsCookies=" + acceptsCookies;
Response.Redirect(url);
}
¿你能後的代碼? – 2012-03-07 18:14:11
其實整個代碼都可以在我鏈接到的文檔中找到。 – KoturB 2012-03-08 07:05:12