简体   繁体   English

使用WCF Web API Preview 6的基本身份验证

[英]Basic Authentication with WCF Web API Preview 6

I'm trying to use the new WCF Web API Preview 6 with Basic Authentication. 我正在尝试将新的WCF Web API Preview 6与基本身份验证一起使用。 But don't really know where to begin. 但是真的不知道从哪里开始。

zanewill apparently had the same issue: zanewill显然有相同的问题:
https://stackoverflow.com/questions/8304367/how-to-use-basic-authentication-with-wcf-web-api But the question is not a dup. https://stackoverflow.com/questions/8304367/how-to-use-basic-authentication-with-wcf-web-api但是问题不是重复。 I'm using this with mvc and don't really see how 我将其与mvc一起使用,但真的看不到
Wcf Basic authentication Wcf基本身份验证
should apply? 应该申请?

I've tried out this: 我已经尝试过了:
http://cacheandquery.com/blog/2011/03/customizing-asp-net-mvc-basic-authentication/ http://cacheandquery.com/blog/2011/03/customizing-asp-net-mvc-basic-authentication/
But can't get it to work. 但是无法使其正常工作。 Should there not be an official solution from MS? MS是否应提供正式解决方案?

I have to note, that we are using our custom membership provider and that I basically just wanna pass an API token to the service. 我必须指出,我们正在使用我们的自定义成员资格提供程序,并且我基本上只是想将API令牌传递给该服务。 So the built in Windows Basic Authentification cannot be used. 因此无法使用内置的Windows Basic身份验证。

I actually figured out a way myself. 我实际上自己想办法。 I've built my custom HttpOperationHandler and combined it with an Attribute, so I get a similar functionality as the MVC AuthorizeAttribute. 我已经构建了自定义HttpOperationHandler并将其与Attribute结合使用,因此获得了与MVC AuthorizeAttribute相似的功能。

You can have a look at the solution here: 您可以在这里查看解决方案:
http://remy.supertext.ch/2012/02/basic-authentication-with-wcf-web-api-preview-6/ http://remy.supertext.ch/2012/02/basic-authentication-with-wcf-web-api-preview-6/

I think the recommended approach is to implement custom message handler. 我认为推荐的方法是实现自定义消息处理程序。 See my blog post for an example that works with ASP.NET Web API RTM: 有关适用于ASP.NET Web API RTM的示例,请参见我的博客文章:

http://www.piotrwalat.net/basic-http-authentication-in-asp-net-web-api-using-message-handlers/ http://www.piotrwalat.net/basic-http-authentication-in-asp-net-web-api-using-message-handlers/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM