page specific cookie page specific cookie

You want to set values in cookie, which is valid for page path "/mysubdirectory". Here is example in to set page path specific cookie. C# cookie path example.

protected void Page_Load(object sender, EventArgs e)

HttpCookie UserNameCookie = new HttpCookie("UserName");
UserNameCookie.Value = "Satalaj";
UserNameCookie.Path = "/web.Demo";


protected void Button1_Click(object sender, EventArgs e)
string username = Request.Cookies["UserName"].Value;

Response.Write("Retrived user name from cookie is: " + username);
} Cookie path Example.

Protected Sub Page_Load(sender As Object, e As EventArgs)

Dim UserNameCookie As New HttpCookie("UserName")
UserNameCookie.Value = "Satalaj"
UserNameCookie.Path = "/web.Demo"


End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs)
Dim username As String = Request.Cookies("UserName").Value

Response.Write("Retrived user name from cookie is: " + username)
End Sub

What you need to do is, just set path of instance of Http Cookie.

Tags: How To Write a Cookie and How To Remove How To Expire a Cookie[] Get current Page URL absolute URI and query string parameters.asp net image Interview Questions for 2 years or 3 years File 2.0 step by step Membership Provider Sessions In Convert String To forms authentication


My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.

I'm Satalaj.