【问题标题】:HttpContext.Current.User is null when IsOneWay = true当 IsOneWay = true 时,HttpContext.Current.User 为空
【发布时间】:2013-03-11 11:12:00
【问题描述】:

我有 wcf 服务。有些是一种方式,有些不是。 那些不是使用表单身份验证的一种方式,我得到 HttpContext.Current.User。 那些是一种方式的方法在 HttpContext.Current.User 中获得 null。

如何解决?

我正在使用 ASP.NET 兼容模式

【问题讨论】:

    标签: c# .net-4.0 forms-authentication isoneway


    【解决方案1】:

    通过HttpContext.Current is null in my web service:

    WCF Services and ASP.NET

    在 AppDomain 中,由 HTTP 运行时实现的功能适用于 ASP.NET 内容,但不适用于 WCF。 ASP.NET 应用程序平台的许多 HTTP 特定功能不适用于托管在包含 ASP.NET 内容的 AppDomain 内的 WCF 服务。这些功能的示例包括:

    HttpContext:从 WCF 服务中访问时,Current 始终为空。请改用RequestContext

    [...]

    HttpContext:在 ASP.NET 兼容模式下运行的 WCF 服务可以访问 Current 及其关联状态。

    【讨论】:

    • 你的意思是OperationContext.Current.RequestContext1?这个也是空的。无论如何,我需要访问“HttpContext.Current.User”属性。
    • “无论如何我需要访问 'HttpContext.Current.User' 属性。” - 不,您需要获取当前登录的用户。如果那不在该属性中并且已记录在案,则您需要查看其他地方。另请参阅编辑,查看 ASP.NET 兼容模式。
    • 好吧,如果您不希望这成为猜测游戏,那么用您尝试过的内容和配置来编辑您的问题可能会很有用。
    猜你喜欢
    • 2011-01-11
    • 1970-01-01
    • 2012-05-06
    • 1970-01-01
    • 1970-01-01
    • 2012-12-04
    • 1970-01-01
    • 2013-02-26
    • 1970-01-01
    相关资源
    最近更新 更多