Ludmal De Silva - .Net Programmer

Ludmal De Silva - .Net Programmer

Share this post

Ludmal De Silva - .Net Programmer
Ludmal De Silva - .Net Programmer
ASP.Net Cookie Handling
Copy link
Facebook
Email
Notes
More

ASP.Net Cookie Handling

Ludmal De Silva's avatar
Ludmal De Silva
May 12, 2005

Share this post

Ludmal De Silva - .Net Programmer
Ludmal De Silva - .Net Programmer
ASP.Net Cookie Handling
Copy link
Facebook
Email
Notes
More
Share

Recently i came across with a problem with HtttpCookies. I try to save the client information in a cookie. But i couldnt, so i was just trying to check whether cookie is enable or not in the client browser. I simply used Request.Browser.Cookies property. But it didnt gave me the result that i wanted. Then i realized Request.Browser.Cookies is for checking the Browser capability of handling cookies. I coudn't find anything which tells me browser cookies are enable or disable . So what i did was just simply tried to create a cookie & tried to read the value from it. Below u will find the code for the two pages i used to solved the problem. If you guys have better solutions than this pls let me know.

//Page 1
//Page Load Event

if(!IsPostBack)
{
if(Request.QueryString["AcceptCookies"] == null)
{
Response.Cookies["TestCookie"].Value = "ok";
Response.Cookies["TestCookie"].Expires = DateTime.Now.AddMinutes(1);
Response.Redirect("My2.aspx?redirect=" + Server.UrlEncode(Request.Url.ToString()));
}
else
{
//Can Redirect to the page You want
Response.Write(Request.QueryString["AcceptCookies"].ToString());
}
}


//Page2
//Page Load Event

string redirect = Request.QueryString["redirect"];
string acceptCookies = "";
if(Request.Cookies["TestCookie"] == null)
{
//No Cookies
acceptCookies = "0";
}
else
{
//Yes Cookies
acceptCookies = "1";
//Delete the Test Cookies
Response.Cookies["TestCookie"].Expires = DateTime.Now.AddMinutes(1);
}
Response.Redirect(redirect + "?AcceptCookies=" + acceptCookies );


Subscribe to Ludmal De Silva - .Net Programmer

Launched a year ago
Hello there, I have written many software applications mainly using .Net tech and has a great passion for AI.

Share this post

Ludmal De Silva - .Net Programmer
Ludmal De Silva - .Net Programmer
ASP.Net Cookie Handling
Copy link
Facebook
Email
Notes
More
Share

Discussion about this post

User's avatar
Event-Driven Microservices Architecture with .NET
Microservices have gained immense popularity due to their scalability, flexibility, and alignment with modern distributed systems.
Sep 6, 2024 â€¢ 
Ludmal De Silva
1

Share this post

Ludmal De Silva - .Net Programmer
Ludmal De Silva - .Net Programmer
Event-Driven Microservices Architecture with .NET
Copy link
Facebook
Email
Notes
More
Azure Service Bus Queue RetryOptions
It's crucial to effectively handle transient errors during message processing.
Nov 15, 2023 â€¢ 
Ludmal De Silva

Share this post

Ludmal De Silva - .Net Programmer
Ludmal De Silva - .Net Programmer
Azure Service Bus Queue RetryOptions
Copy link
Facebook
Email
Notes
More
.NET Configuration with IOptions, IOptionsMonitor, and IOptionsSnapshot
Configuration management is a critical aspect of modern software development.
Jan 31, 2024 â€¢ 
Ludmal De Silva

Share this post

Ludmal De Silva - .Net Programmer
Ludmal De Silva - .Net Programmer
.NET Configuration with IOptions, IOptionsMonitor, and IOptionsSnapshot
Copy link
Facebook
Email
Notes
More

Ready for more?

© 2025 Ludmal De Silva
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share

Copy link
Facebook
Email
Notes
More

Create your profile

User's avatar

Only paid subscribers can comment on this post

Already a paid subscriber? Sign in

Check your email

For your security, we need to re-authenticate you.

Click the link we sent to , or click here to sign in.