I decided to re-write the question as I found some info on how to accomplish the above: http://msdn.microsoft.com/en-us/library/aa289495%28v=vs.71%29.aspx
However, my problem is that I'm trying to do all that on the Page_Load
event of Login.aspx.cs
.
Initially it appears to be working fine until I attempt to actually log in by entering my credentials and clicking the Login button. Then all hell breaks lose and I get an endless loop. It keeps going back and forth between Page_Loads on Login.aspx.cs
and TestForCookies.aspx.cs
. Each time Redirect URL grows by another "?AcceptCookies=1
". Is there a work around to this?
Login.aspx.cs code:
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 code:
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);
}
This can be hairy. What I've done on my login page is basically these steps:
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With