Workaround for httpcontext.current NULL in WCF

Source: Internet
Author: User
Tags hosting

Resolve WCF hosting IIS in the environment so that httpcontext.current is not NULL, we pass the cookie in each request

After the test found that just pay attention to the following highlights:

1. In hosting WCF, in Web. config, add:

<system.serviceModel>
<servicehostingenvironment aspnetcompatibilityenabled= "true"/>
</system.serviceModel>


2. In the definition of each service (note that it is not contract, but even if the compilation on contract will also error), add the following attribute:

[Aspnetcompatibilityrequirements (Requirementsmode = aspnetcompatibilityrequirementsmode.allowed)]


Again, you can see that HttpContext.Current is also available in programs that find WCF hosting IIS.

Workaround for httpcontext.current NULL in WCF

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.