发送授权cookie调用的OData服务时, [英] Send Authorization cookie when calling OData service

查看:207
本文介绍了发送授权cookie调用的OData服务时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个Web应用程序。结果
第一个Web应用程序包含ASP.NET网页和用于身份验证的成员资格提供程序。结果
第二个Web应用程序是严格意义上的WEB OData的API网站需要身份验证。

这两个网站都有相同的的machineKey的validationKey / decryptionKey中的web配置无一不是通过表单以

同样的.TESTAUTH的形式命名为认证

当我打电话的OData服务,并检查身份为螺纹和的HttpContext它们都是空的名称和isauthenticated。

那么,如何得到的OData承认.TESTAUTH饼干吗?

结果搜索结果
编辑:结果
那么这里是我做的。它似乎不正确的,但如果有人知道更好的方法,请让我知道。

  dbContext.BuildingRequest + =的addCookie;
私人无效的addCookie(对象发件人,Microsoft.OData.Client.BuildingRequestEventArgs E)
{
    变种authCookie = HttpContext.Current.Request.Cookies(。TESTAUTH);    e.Headers.Add(曲奇,.TESTAUTH =+ authCookie.Value);
}


解决方案

下面是我做过什么来解决这个问题。

  dbContext.BuildingRequest + =的addCookie;
私人无效的addCookie(对象发件人,Microsoft.OData.Client.BuildingRequestEventArgs E)
{
    变种authCookie = HttpContext.Current.Request.Cookies(。TESTAUTH);    e.Headers.Add(曲奇,.TESTAUTH =+ authCookie.Value);
}

I have 2 web applications.
The first web application contains ASP.NET web pages and used a Membership provider for authentication.
The second web application is strictly an OData WEB API site that requires authentication.

Both sites have the same "machineKey validationKey / decryptionKey" in the web config and both are using "Forms" authentication with the same "forms name of .TESTAUTH"

When I call the OData service and inspect the IDentity for both the thread and httpcontext they are both empty for the name and isauthenticated.

So how do I get the OData to recognize the .TESTAUTH cookie?




EDIT:
Well here is what I did. It doesn't seem right but if someone knows a better way please let me know.

dbContext.BuildingRequest += AddCookie;
private void AddCookie(object sender, Microsoft.OData.Client.BuildingRequestEventArgs e)
{       
    var authCookie = HttpContext.Current.Request.Cookies(".TESTAUTH");

    e.Headers.Add("Cookie", ".TESTAUTH=" + authCookie.Value);
}

解决方案

Here is what I did to solve the problem.

dbContext.BuildingRequest += AddCookie;
private void AddCookie(object sender, Microsoft.OData.Client.BuildingRequestEventArgs e)
{       
    var authCookie = HttpContext.Current.Request.Cookies(".TESTAUTH");

    e.Headers.Add("Cookie", ".TESTAUTH=" + authCookie.Value);
}

这篇关于发送授权cookie调用的OData服务时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆