How to set ServiceHostingEnvironment.AspNetCompatibilityEnabled = true in Code (not in config) .NET/C#

前端 未结 5 1685
南笙
南笙 2021-02-03 11:09

I have a requirement to access the HttpContext.Current from with-in a RESTful WCF service. I know I am able to achieve this by adding the following to config:

&         


        
5条回答
  •  [愿得一人]
    2021-02-03 11:56

    It's an AppDomain-wide setting that you can set on the static ServiceHostingEnvironment class in System.ServiceModel:

     ServiceHostingEnvironment.AspNetCompatibilityEnabled = true;
    

    This should be done before you create and open your service hosts.

    Would have been nice - but it's a read-only setting, and the only way to set it appears to be through configuration :-(

提交回复
热议问题