如何筛选在asp.net网页API本地请求? [英] How to filter local requests in asp.net web api?
问题描述
我具有越来越那种恼人用asp.net网页API的情况。事情是我有一个API,它已经在生产,但是我不断做出改变并重新部署。
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.
我有一个过滤器,它负责检查,如果请求是HTTPS,即生产工作真棒,但是当请求当地过滤器阻止所有的HTTP请求,这是不是我想要的。我想,以允许与HTTP本地的请求。我有一个过滤器,它确实在MVC3完全一样的东西,我可以这样做:
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?
推荐答案
如果您使用的是虚拟主机提供商即在asp.net中托管的WebAPI,您可以访问HttpContext的使用
if you are using webhost i.e hosting webapi in asp.net, you can access the HttpContext using
HttpContextBase httpContextBase;
request.Properties.TryGetValue("MS_HttpContext", out httpContextBase);
您就可以使用 httpContextBase.Request.IsLocal
来确定请求是否是本地的。
You can then use httpContextBase.Request.IsLocal
to determine if the request is local.
这篇关于如何筛选在asp.net网页API本地请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!