开发者

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

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.


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"];


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.


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" />


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜