Require SSL in WebApi?

后端 未结 6 1910
夕颜
夕颜 2020-12-07 15:31

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

I don\'t see an applicable attribute under System.Web.Http, something like the RequireHttp

6条回答
  •  误落风尘
    2020-12-07 16:21

    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)...
    }
    

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

提交回复
热议问题