在同一主机上的两个应用程序之间共享cookie吗

时间:2022-10-27 21:47:13

I have two application hosted on my machine with urls as below.

我的机器上有两个应用程序,url如下所示。

"//mymachine:port1/appl"
"//mymachine:port2/app2"

" / / mymachine:端口1 /:" / / mymachine:端口2 / app2”

Both App1 and app2 use same login credentials. My problem is that when user logs out of App2, app1 also seems to be logged out and redirects to login page. Is there some settings in IIS so that a logout in App2 does not affect App1.

App1和app2都使用相同的登录凭证。我的问题是,当用户从App2注销时,app1似乎也被注销并重定向到登录页面。IIS中是否有一些设置,以使App2中的登出不会影响App1。

3 个解决方案

#1


2  

Browser stores cookies base on Domain name and Path, if you pay attention to cookie tab of firebug you see that session cookies of localhost stores in localhost domain name. So two application have same cookies. but you can store application cookies on different path.

浏览器根据域名和路径存储cookie,如果注意firebug的cookie选项卡,可以看到localhost域名中存储的会话cookie。两个应用程序有相同的cookie。但是您可以在不同的路径上存储应用程序cookie。

Response.Cookies.Add(new HttpCookie("Data")
{
    Value = "....",
    Path = "/app1"
});

Response.Cookies.Add(new HttpCookie("Data")
{
    Value = "....",
    Path = "/app2"
});

在同一主机上的两个应用程序之间共享cookie吗在同一主机上的两个应用程序之间共享cookie吗

#2


0  

if you use session for logins in both the application ,your problem will be solved

如果您在两个应用程序中使用会话进行登录,那么您的问题将得到解决

for example create session as

例如创建会话as

session["email"] = emailtextbox.text

create it in both the application and check the session in each and every form thats it

在应用程序中创建它,并在每个表单中检查会话

#3


0  

Finally solved the issue by setting different paths to forms authentication cookie.

最后通过设置不同的路径来实现表单验证cookie。

In app1 set as

在app1设置为

<authentication mode="Forms">
      <forms loginUrl="~/MyController/MyAction" timeout="60" path="/"/>
    </authentication>

In app2 set as

在app2设置为

<authentication mode="Forms">
      <forms loginUrl="~/MyController/MyAction" timeout="60" path="/SomeOtherPath"/>
    </authentication>

#1


2  

Browser stores cookies base on Domain name and Path, if you pay attention to cookie tab of firebug you see that session cookies of localhost stores in localhost domain name. So two application have same cookies. but you can store application cookies on different path.

浏览器根据域名和路径存储cookie,如果注意firebug的cookie选项卡,可以看到localhost域名中存储的会话cookie。两个应用程序有相同的cookie。但是您可以在不同的路径上存储应用程序cookie。

Response.Cookies.Add(new HttpCookie("Data")
{
    Value = "....",
    Path = "/app1"
});

Response.Cookies.Add(new HttpCookie("Data")
{
    Value = "....",
    Path = "/app2"
});

在同一主机上的两个应用程序之间共享cookie吗在同一主机上的两个应用程序之间共享cookie吗

#2


0  

if you use session for logins in both the application ,your problem will be solved

如果您在两个应用程序中使用会话进行登录,那么您的问题将得到解决

for example create session as

例如创建会话as

session["email"] = emailtextbox.text

create it in both the application and check the session in each and every form thats it

在应用程序中创建它,并在每个表单中检查会话

#3


0  

Finally solved the issue by setting different paths to forms authentication cookie.

最后通过设置不同的路径来实现表单验证cookie。

In app1 set as

在app1设置为

<authentication mode="Forms">
      <forms loginUrl="~/MyController/MyAction" timeout="60" path="/"/>
    </authentication>

In app2 set as

在app2设置为

<authentication mode="Forms">
      <forms loginUrl="~/MyController/MyAction" timeout="60" path="/SomeOtherPath"/>
    </authentication>