简体   繁体   中英

IIS 7, folders converted to application and cookies not working

A new, probably, unsolved and easy to recreate problem with IIS 7, applications, and cookies for you. The main point is that cookies are not SENT from IIS7 if you set the cookie from one folder and then request it from another, on the same website obviously, if one of the two folders has been set as "convert to application" from IIS 7.

Steps to reproduce the problem:

1) Create a "setcookie.asp" (CLASSIC ASP) with the following code:

response.cookies("mycookie")="myvalue"
response.cookies("mycookie").expires=dateadd("d",3650,now())

2) Create a "readcookie.aspx" with the following code:

protected void Page_Load(object sender, EventArgs e)
{
HttpCookie myCookie = Request.Cookies["mycookie"];
if (myCookie!=null)
response.write(myCookie.Value);
else
response.write("NULL COOKIE");
}

3) Create a new IIS 7 website with two subfolders: "folderone" and "foldertwo".

4) On the root, put the "writecookie.asp", then copy "readcookie.aspx" on both "folderone" and "foldertwo".

5) go to http://yourwebsite/setcookie.asp you set the cookie - OK - then go to http://yourwebsite/folderone/readcookie.aspx : it works and shows the cookie content. This works also from http://yourwebsite/foldertwo/readcookie.aspx

Now, the fun:

On IIS 7 right click on "foldertwo" and select "convert to application", and try again step 5): the "folderone/readcookie.aspx" will return the correct cookie, but "foldertwo/readcookie.aspx" will return "NULL" !!!!!!!

If you do the same on IIS6 the cookie works perfectly among different applications.

Is there any solution ? It seems it's exactly the same problem as having an "app_code" shared between applications (that is impossibile: you need to copy+paste the "app_code" folder under every single application folder you set).

Thanks anyone.

As far as I am aware that cookies are Application dependent ie cookies life cycle exist for that particular site.

Now when you convert folder into application its a new application and a new website, so it won't be treated as same website, that's why you are not able to find values for the same.

Alternatively, you can explore cookies by locating their text files on your hard disk. Internet Explorer stores the cookies for a site in a file whose name is in the format @.txt, where is your account name. For example, if your name is mikepope and you visit the site www.contoso.com, the cookies for that site will be in a file called mikepope@www.contoso.txt. (The name might include a sequential number, such as mikepope@www.contoso[1].txt.)

Since you converted your folder into its own application you need to set the cookie path.

    Dim myCookie As HttpCookie
myCookie = New HttpCookie("LastVisit", DateTime.Now.ToString())
myCookie.Path += "; HttpOnly"
Response.AppendCookie(myCookie)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM