access HttpContext.Current from WCF Web Service

后端 未结 3 2033
遥遥无期
遥遥无期 2020-12-02 15:37

I just started using WCF Services with ASP.NET AJAX. I instantiate my WCF service from Javascript and then pass string variables as arguments to my WCF Service method (with

3条回答
  •  庸人自扰
    2020-12-02 16:27

    You can get access to HttpContext.Current by enabling AspNetCompatibility, preferably via configuration:

    
      
        
      
    
    

    That in turn allows you to get access to the current user: HttpContext.Current.User - which is what you're after, right?

    You can even enforce AspNetCompatibility by decorating your service class with an additional attribute:

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    

    (In the System.ServiceModel.Activation namespace.) If that attribute is in place, your service will fail to start unless AspNetCompatibility is enabled!

提交回复
热议问题