将 cookie 传递给 wcf 服务

发布于 2024-10-30 05:14:40 字数 836 浏览 9 评论 0原文

我有一堆 wcf webhttp (rest) 服务需要身份验证 cookie。问题是 - 如何将 formsauth 票证传递给 wcf 服务?流动身份验证适用于通过浏览器获取请求,效果很好(应该如此),但我不确定如何在使用 httpclient 或 webchannelfactory 的调用期间设置 cookie。至此,身份验证完成,cookie 可用。我不确定在通过 HttpClient 调用服务时在哪里插入 cookie。

HttpClient client = new HttpClient();
HttpContent content = 
    HttpContentExtensions.CreateDataContract<EmployeeData>(MyEmployee);
resp = client.Post("http://localhost/someservice", content);

我还尝试按照以下网址使用 webchannelfactory - http://zamd.net/2009/03/05/flowing-forms-authentication-cookie-to-wcf/

但是,var Identity = Thread.CurrentPrincipal.Identity as ClientFormsIdentity; 即使 Thread.CurrentPrincipal.Identity 是有效的 FormsIdentity,也会返回 null。任何建议都会非常有帮助。

I have a bunch of wcf webhttp (rest) services that expect an auth cookie. Question is - How do I pass the formsauth ticket to the wcf service? Flowing authentication works for get requests through the browsers just fine (as it should) but I am not sure how to set the cookie during my calls using httpclient or webchannelfactory. At this point the authentication is done and the cookie is available. I am not sure of where to insert the cookies while invoking the service through a HttpClient.

HttpClient client = new HttpClient();
HttpContent content = 
    HttpContentExtensions.CreateDataContract<EmployeeData>(MyEmployee);
resp = client.Post("http://localhost/someservice", content);

I also tried to use the webchannelfactory as per the following url - http://zamd.net/2009/03/05/flowing-forms-authentication-cookie-to-wcf/

However, var identity = Thread.CurrentPrincipal.Identity as ClientFormsIdentity; returns a null even though the Thread.CurrentPrincipal.Identity is a valid FormsIdentity. Any suggestions would be greatly helpful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文