I have written a simple REST API in WCF, and the authentication mechanism uses an API key. Once the client submits the API key in the request header, I check it on the server side (in the BaseService class overriding the ProcessRequest() method of RequestInterceptor class) as follows:
public partial class BaseService : RequestInterceptor
{
public BaseService() : base(false) { }
#region Process Request
public override void ProcessRequest(ref RequestContext requestContext)
{
if (IsValidApiKey(requestContext))
//put some values in HttpContext object.
}
…
Now I have enabled aspnet compatibility in my REST services, but I still cannot access HttpContext object in the ProcessRequest override above.
Note that HttpContext is accessible from inside a service method, but not in the ProcessRequest method.
Any ideas why?
I have solved my problem by adding following code:
After doing this I am able to access HttpContext object in the ProcessRequest method.