Is it possible to access cookies which exists on another application in IIS?

我的未来我决定 提交于 2019-12-11 09:52:26

问题


I have 2 website on my IIS7, I can put the same domain for both of them, I want some cookies of both applications to be shared between them, so than I can create the cookie from one of them and read it from the other one, is that possible? do I need any custom configurations to do that?

note: My websites, 1 is asp.net forms website and the other is MVC.


回答1:


When you create the cookie specify the domain:

var cookie = new HttpCookie("foo", "bar")
{
    // indicates that only server side scripts can read this cookie
    HttpOnly = true,

    // indicates that the cookie will be available throughout the entire domain
    Domain = "example.com"
};
Response.AppendCookie(cookie);

Now on the other application you will be able to access this cookie (assuming of course it is running on the same domain):

var cookie = Request.Cookies["foo"];



回答2:


Cookies are sent by the client to any URL in the cookie's domain (and optional path).

They have nothing to do with the server-side application; as long as the application is in the cookie's domain name and path, it will receive all cookies.




回答3:


If both applications are in top level, there is no need for any custom configuration but if any of the application is in sub domain, than you have properly set cookie so that sub-domains can access that. In that case, following web.config modification is needed.

<httpCookies domain=".yourdomain.com" />



回答4:


yes if there are appending cookie not only add like: Response.AppendCookie(your cookie name) Remember that if it is in asp.net web site then you can get cookie by string a = Request.Cookies["Your Cookie Name"].Value some thing like that



来源:https://stackoverflow.com/questions/6269354/is-it-possible-to-access-cookies-which-exists-on-another-application-in-iis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!