I could not say if this is the "best" way but one way I see often is to write
a test cookie on page load and then post back to the same url checking if you
can retrieve the cookie. The code below is from the forums on asp.net and
posted by Fredrik Normen. It illustrates in general how this strategy could
be implemented.
Hopefully you can use something like this to solve your problem. Otherwise,
you might have to use javascript to check if cookies are enabled and then
post that to a form/url to be stored in the session state.
Good Luck.
================================================== =
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsCookieDisabled())
errorMsgLabel.Text = Resources.Resource.BrowserDontSupportCookies;
}
private bool IsCookieDisabled()
{
string currentUrl = Request.RawUrl;
if (Request.QueryString["cookieCheck"] == null)
{
try
{
HttpCookie c = new HttpCookie("SupportCookies", "true");
Response.Cookies.Add(c);
if (currentUrl.IndexOf("?") 0)
currentUrl = currentUrl + "&cookieCheck=true";
else
currentUrl = currentUrl + "?cookieCheck=true";
Response.Redirect(currentUrl);
}
catch
{
}
}
if (!Request.Browser.Cookies || Request.Cookies["SupportCookies"] ==
null)
return true;
return false;
}
================================================== =
"BL" wrote:
if (Request.Browser.Cookies)
{
// Cookies supported
}
else
{
// Web browser not supports cookies
}
Code above will tell you does web browser supports cookie technology, but a
visitor could disable cookies in web browser's privacy settings. In that
case, Request.Browser.Cookies will still return true but your cookies will
not be saved.
what is the best way in asp.net 2.0 to check cookies disable or enabled in
web browser's privacy settings ?
Thank you.
BL