[英]ASP.NET Send Cookies to client Browser
I'm integrating a single sign on over 2 ASP.Net applications.我在超过 2 个 ASP.Net 应用程序上集成了单点登录。 For that matter i have a web service that is called by the main app.
就此而言,我有一个由主应用程序调用的 web 服务。 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 so he can navigate freely and logged in both applications.
当用户登录时。此 web 服务在我的第二个应用程序中对用户进行身份验证,并带回我需要提供给客户端浏览器的身份验证 cookies,以便他可以自由导航并登录这两个应用程序。
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...我打算使用HttpContext.Current.Response.Cookies.Add(cookie)来交付新的 cookies 但这似乎不起作用,因为没有 cookies 添加了什么...
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注意: CookieConverter(item)用于将我收到的 Cookie object 转换为 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:你应该检查:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.