HttpContext.Current is null when checked on interc

2019-09-01 07:38发布

问题:

My asp.net application have form authentication. When user logs in, he is redirected to a new page abc.aspx. On this page, in javascript, on document.ready, a service call is made to some service which have AspNetCompatibilityMode on. In the interceptor of the service, I try to find the HttpContext.Current but when its the first request to the application, interceptor does not get HttpContext.Current and is found null. After that, its never null but only on the first request to the application.

回答1:

If you use WCF, in the wcf there is no HttpContext.Current. You have to use the InstanceContextMode of the Service class in the Session.



回答2:

Correctly said by Peer, there is no HttpContext in WCF. You may use OperationContext.Current.RequestContext

You would have to follow below link

http://www.danrigsby.com/blog/index.php/2008/05/23/understanding-instancecontext-in-wcf/