C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to identify cookies disabled


Posted Date: 03 Jul 2008      Total Responses: 3

Posted By: kumar       Member Level: Gold     Points: 1



Hi,

My requirement is if the user is disabled the cookies in the brower

Warning msg is shown in the ErrMsg label. Would any solve my problem?

I was tried this way but ErrMsg is not shown.

1st i disable cookies in the browser Tools - InternetOpt -- privacy
then follow write the following code.

protected void Page_Load(object sender, EventArgs e)
{
string key1 = "cookieAuthtoken1"; //Encrypt(key);
string value1 = "kk";//Encrypt(value);
HttpCookie cke;
cke = new HttpCookie(key1, value1);
cke.Expires = DateTime.MaxValue;
Response.Cookies.Add(cke);

if(Response.Cookies["cookieAuthtoken1"]==null)
{
Label.text = Please enable the cookies in the browser;
}
//Response.Write(Response.Cookies["cookieAuthtoken1"].Value.ToString());
Response.End();
}

If i disable the cookie in the browser but the cookie is created,
how i solve this problem.

regards
kk






Responses

Author: Payal Jain    04 Jul 2008Member Level: GoldRating:     Points: 6

The following code example shows how to detect blocked cookies in C#. This code would be placed within the first page users will access on your site (usually default.aspx or Global.ascx).

// Cookie detection.
// Is our cookie not yet set and the url parameter empty? If so, lets set the cookie.
if (Session["CookieCheck"] == null && Request.QueryString["c"] == null)
{
// Set the cookie and redirect so we can try to detect it.
Session["CookieCheck"] = "1";
Response.Redirect("default.aspx?c=1", true);

return;
}
else
{
// Detect the cookie.
if (Session["CookieCheck"] == null || Session["CookieCheck"].ToString() != "1")
{
// Cookies are disabled
Response.Redirect("NoCookies.aspx", true);
return;
}
}

Upon detecting that a user is blocking cookies, the user will be redirected to a NoCookies.aspx page. This page can notify the user in a friendly manner that the web application requires cookies and provide steps to enable them.




Author: Payal Jain    04 Jul 2008Member Level: GoldRating:     Points: 0

http://www.aspfaqs.com/webtech/082400-1.shtml


Author: kumar    04 Jul 2008Member Level: GoldRating:     Points: 1

Hi,

tks for ur response but this is not working and ur creating the session not cookies.

kk



Post Reply
You must Sign In to post a response.
Next : Tabindex not working on Safari(MAC os)
Previous : Cookie encryption
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use