无法使FormsAuthentication正确使用WCF

时间:2010-04-15 14:46:34

标签: asp.net wcf forms-authentication .aspxauth

我在同一个项目中同时拥有wcf和asp.net项目。 (我在Azure上运行,所以这更方便)。

我在web.config中设置了这个:

<system.serviceModel>  
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 
</system.serviceModel>

我的wcf服务装饰有:

[AspNetCompatibilityRequirements(
    RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

设置了这些属性后,当我在wcf服务中运行方法时,不应该为我自动设置HttpContext.Current.User吗?目前,HttpContext.Current.User为null,不会自动为我设置。

我想如果我使用了aspNetCompatibilityEnabled,那么当执行wcf方法时,Application_AuthenticationRequest方法会在Global.asax中触发,但事实并非如此。

.aspxauth cookie正确传递给wcf服务,我能够手动解密cookie并设置当前用户。

建议为什么这不符合我的预期?

1 个答案:

答案 0 :(得分:0)

您是否在

中获得了预期的用户身份
ServiceSecurityContext.Current.PrimaryIdentity

在服务器方法代码中可用的字段?它应该是某种形式的IIdentity后代,为您提供用户信息(如果有)。

相关问题