I'm having a situation that is getting kind of annoying with asp.net web api. The thing is i have an API which is already in production, however I'm constantly making changing and deploying again.
I have a filter, which takes care of checking if the request is https, that works awesome on production, but when requests are local the filter blocks all http requests, which is not what I want. I would like to allow local requests with http. I have a filter which does the exact same thing on MVC3, and I can do something like:
filterContext.HttpContext.Request.IsLocal
Is there any work around to this problem?
You can directly use the IsLocal extension method of the HttpRequestMessage. link
For example:
MS_Islocal property was not available to me instead this worked -
if you are using webhost i.e hosting webapi in asp.net, you can access the HttpContext using
You can then use
httpContextBase.Request.IsLocal
to determine if the request is local.You can use an extension method to access the value within the Request.Properties Dictionary. For example:
This has the added benefit of also working when self-hosting.