开发者

ASP.NET Send Cookies to client Browser

I'm integrating a single sign on over 2 ASP.Net applications. For that matter i have a web service that is called by the main app. when a user logs in. this web service authenticates the user in my second application and brings back the authentication cookies i need to deliver to the client browser开发者_Go百科 so he can navigate freely and logged in both applications.

I was planning to use HttpContext.Current.Response.Cookies.Add(cookie) in order to deliver the new cookies but this seems not to work as no cookies are added what so ever...

Any ideas on what might be going wrong?

here is my code:

var service = new localhost.UserManagement();
service.CookieContainer = new CookieContainer();
if (service.AuthenticateUser("test@user.pt", "test"))
{ 
    var collection = service.CookieContainer.GetCookies(new Uri("http://localhost"));
    foreach (Cookie item in collection)
    {
        HttpContext.Current.Response.Cookies.Add(CookieConverter(item));
    }
    HttpContext.Current.Response.Flush();
    return true;
}

return false;

Note: CookieConverter(item) is used to convert Cookie object i receive to HttpCookie

Thanks


private HttpCookie CookieConverter(Cookie cookie)
        {
            var result = new HttpCookie(cookie.Name);

            result.Value = cookie.Value;
            result.Domain = cookie.Domain;
            result.Expires = cookie.Expires;
            result.Path = cookie.Path;
            result.Secure = cookie.Secure;
            result.HttpOnly = cookie.HttpOnly;

            return result;
        }


You should check:

  • collection is empty? Could you set braeakpoint and check collection?
  • where is this code located? (.aspx page, web service, http handler?)
  • try to create minimalistic "Cookie setter" that just add simple cookie in any way
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜