小编arg*_*yle的帖子

将HttpContext.Current.User.Identity传递给WCF

寻找一些建议(或者甚至是直接回答).

我有一个MVC3网站.我还有一组运行的WCF服务(现在一切都在同一个盒子里).

我正在试图做的是验证客户端(即部分工作正常),然后通过该认证的用户在各种WCF调用.

目前我已经将Application_AuthenticateRequest()方法连接起来Global.Asax,归结为创建一个新方法GenericIdentity & GenericPrincipal,然后将该主体分配给HttpContext.Current.User:

...
GenericIdentity identity = new GenericIdentity(userName);
GenericPrincipal principal = new GenericPrincipal(identity, null);
HttpContext.Current.User = principal;
...
Run Code Online (Sandbox Code Playgroud)

而那部分似乎也运作良好.

但是当我点击我的服务时,我完全失去了我设置的用户.值为空或假.

我注意到的一个主要问题是,在客户端,HttpContext.Current.User.Identity对象是类型{System.Web.Security.FormsIdentity},但在服务中它是类型{System.Security.Principal.WindowsIdentity}.

根据我读过的一些内容,听起来就像修改我的内容web.config所以它包含的内容aspNetCompatibilityEnabled="true"可能足以使其正常工作.但那不是我所看到的.所以要么我不理解一切(非常好的可能性),要么我搞砸了(另一种可能性很大).

所以我的问题.这是否可能,如果是这样的话 - 想想我错过了什么?我注意到其他一些人发布了类似的东西,但从来没有得到明确的答案(见这里这里).

任何建议都非常感谢.

authentication cookies asp.net-mvc wcf httpcontext

6
推荐指数
1
解决办法
3329
查看次数

标签 统计

asp.net-mvc ×1

authentication ×1

cookies ×1

httpcontext ×1

wcf ×1