我如何能实现在Asp.Net的Web API HTTPS / SSL连接? [英] How can I implement Https/SSL connection on Asp.Net Web API?

查看:631
本文介绍了我如何能实现在Asp.Net的Web API HTTPS / SSL连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Asp.net的Web API,提供的API客户端(iPhone,Android手机,MAC OS,网络,窗口,...)。我想实现更多的安全感,这是我prevent其他一些了解的链接参数(在情况下,他们破解链接)

I use Asp.net web APIs to provide apis to client (iphone, android, mac os,web,windows,...). I want to implement some API with more security, which I prevent some other understand the parameter in the link (in case they hack the link)

我的问题是:我可以使用HTTPS / SSL这个?是否足够安全?如果是的话,我应该安装任何东西在客户端来实现这一点?

My question is: Can I use Https/SSL for this? Is it enough secure? If yes, Should I install any thing at client side to implement this?

感谢

推荐答案

这取决于你要去哪里举办您的ASP.NET Web API应用。如果你要举办这IIS下,你不需要做什么特别的东西不是通过IIS配置SSL等。

It depends on where you are going to host your ASP.NET Web API application. If you are going to host it under IIS, you don't need to do anything special other than configuring SSL through IIS.

有一件事你应该做的IMO是通过应用程序来强制HTTPS。您可以实现此用不同的方式(如IIS URL重定向模块等),但你也可以做到这一点在同一个消息处理应用程序级:

One thing you should do IMO is to force HTTPS through your application. You can implement this with different ways (such as IIS URL Redirect module, etc.) but you can also do this at the application level with a message handler:

public class RequireHttpsMessageHandler : DelegatingHandler {

    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) {

        if (request.RequestUri.Scheme != Uri.UriSchemeHttps) {

            var forbiddenResponse = request.CreateResponse(HttpStatusCode.Forbidden);
            forbiddenResponse.ReasonPhrase = "SSL Required";
            return Task.FromResult<HttpResponseMessage>(forbiddenResponse);
        }

        return base.SendAsync(request, cancellationToken);
    }
}

的HttpClient 还支持SSL就像任何其他.NET Web客户端。看看这篇文章:<一href=\"http://blogs.msdn.com/b/henrikn/archive/2012/08/07/httpclient-httpclienthandler-and-httpwebrequesthandler.aspx\">http://blogs.msdn.com/b/henrikn/archive/2012/08/07/httpclient-httpclienthandler-and-httpwebrequesthandler.aspx

HttpClient also supports SSL just like any other .NET web clients. Have a look at this article: http://blogs.msdn.com/b/henrikn/archive/2012/08/07/httpclient-httpclienthandler-and-httpwebrequesthandler.aspx

这篇关于我如何能实现在Asp.Net的Web API HTTPS / SSL连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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