需要SSL中的WebAPI? [英] Require SSL in WebApi?

查看:144
本文介绍了需要SSL中的WebAPI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来要求SSL的WebAPI?属性?

Is there a way to require SSL for WebApi? An attribute?

我看不出下一个适用的属性 System.Web.Http ,有点像 RequireHttps 属性我们对MVC。我只是想避开我自己的滚动属性/消息处理程序,如果有一个内置的解决方案。

I don't see an applicable attribute under System.Web.Http, something like the RequireHttps attribute we have for MVC. I'm just trying to avoid rolling my own attribute/ message handler if there is a built in solution.

推荐答案

您可以使用<一个href="https://github.com/WebApiContrib/WebAPIContrib/blob/master/src/WebApiContrib/MessageHandlers/RequireHttpsHandler.cs">RequireHttpsHandler从WebAPIContrib项目。基本上,它的作用是检查传入请求URI方案:

You can use the RequireHttpsHandler from WebAPIContrib project. Basically, all it does is to check the incoming request URI scheme:

if (request.RequestUri.Scheme != Uri.UriSchemeHttps)
{
  // Forbidden (or do a redirect)...
}

另外,卡洛斯·费圭有<一个href="http://blogs.msdn.com/b/carlosfigueira/archive/2012/03/09/implementing-requirehttps-with-asp-net-web-api.aspx">another实施在他的MSDN博客。

Alternately, Carlos Figueira has another implementation on his MSDN blog.

这篇关于需要SSL中的WebAPI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆