简体   繁体   English

IIS 7,文件夹转换为应用程序和cookie无法正常工作

[英]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. IIS 7,应用程序和cookie可能为您解决了一个新的,可能尚未解决且易于重新创建的问题。 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. 要点是,如果您从一个文件夹设置cookie,然后从同一网站上的另一个文件夹请求cookie,则显然不是从IIS7发送cookie,如果两个文件夹之一已从IIS 7设置为“转换为应用程序” 。

Steps to reproduce the problem: 重现此问题的步骤:

1) Create a "setcookie.asp" (CLASSIC ASP) with the following code: 1)使用以下代码创建“ setcookie.asp”(CLASSIC ASP):

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

2) Create a "readcookie.aspx" with the following code: 2)使用以下代码创建“ readcookie.aspx”:

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". 3)创建一个带有两个子文件夹的新IIS 7网站:“ folderone”和“ foldertwo”。

4) On the root, put the "writecookie.asp", then copy "readcookie.aspx" on both "folderone" and "foldertwo". 4)在根目录下,放入“ writecookie.asp”,然后在“ folderone”和“ foldertwo”上复制“ readcookie.aspx”。

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. 5)转到http://yourwebsite/setcookie.asp ,然后设置http://yourwebsite/setcookie.asp确定-然后转到http://yourwebsite/folderone/readcookie.aspx :它可以正常工作并显示cookie内容。 This works also from http://yourwebsite/foldertwo/readcookie.aspx 这也可以从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" !!!!!!! 在IIS 7上,右键单击“ foldertwo”,然后选择“转换为应用程序”,然后重试步骤5):“ folderone / readcookie.aspx”将返回正确的cookie,但是“ foldertwo / readcookie.aspx”将返回“ NULL” “ !!!!!

If you do the same on IIS6 the cookie works perfectly among different applications. 如果您在IIS6上执行相同的操作,则cookie在不同的应用程序之间可以完美地工作。

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). 似乎这与在应用程序之间共享“ app_code”是完全相同的问题(这是不可能的:您需要在设置的每个应用程序文件夹下复制并粘贴“ app_code”文件夹)。

Thanks anyone. 谢谢任何人。

As far as I am aware that cookies are Application dependent ie cookies life cycle exist for that particular site. 据我所知,cookie是依赖于应用程序的,即该特定站点存在cookie生命周期。

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. 另外,您可以通过将cookie的文本文件放在硬盘上来浏览它们。 Internet Explorer stores the cookies for a site in a file whose name is in the format @.txt, where is your account name. Internet Explorer将网站的Cookie存储在一个文件名中,该文件名的格式为@ .txt,即您的帐户名。 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. 例如,如果您的名字是mikepope,而您访问该网站www.contoso.com,则该站点的cookie将位于名为mikepope@www.contoso.txt的文件中。 (The name might include a sequential number, such as mikepope@www.contoso[1].txt.) (名称可能包含序列号,例如mikepope@www.contoso [1] .txt。)

Since you converted your folder into its own application you need to set the cookie path. 由于您已将文件夹转换为自己的应用程序,因此需要设置cookie路径。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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