Wednesday, October 28, 2009

Clear ASP.Net Session from another ASP site

We have a 2 web app under our web site, one is asp.net and another one is asp. After user logout from the ASP web app, we need to make sure the ASP.Net site also been logout.

First we try to use Response.Cookie to delete the ASP.NET_SessionId cookie which issued by ASP.Net, but ASP will automatically encode the ASP.NET_SessionId to ASP%2ENET%5FSessionId which will add a new cookie.

So finally we use the Response.AddHeader "Set-Cookie","ASP.NET_SessionId=deleted;Path=/" to solve the problem

Write Cookie without Encode from ASP

In ASP, if you using Server.Cookie to add or change any cookie, the name and value of the cookie will be urlencode by ASP automatically. So if you call Server.Cookie("my.cookie") = "my_cookie", then on the browser, you will get my%2Ecookie = my%5Fcookie.

So you can use Response.AddHeader "Set-Cookie", "my.cookie=my_cookie" and you will get exact the name and value on your browser.