如何在asp.net web api中设置标头值 [英] How to set header value in asp.net web api
本文介绍了如何在asp.net web api中设置标头值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello house,
我希望能够在asp.net web api中设置标题值/密钥,这样任何人都不能只使用网页服务除了他或她有密钥,并且,如果我可以在api端设置这个,用户如何在客户端检索此值/密钥并在使用服务时使用它。
i试过这个,但不确定我是否正确。以下是我的代码:
Hello house,
I want to be able to set header value/secret key in asp.net web api, so that anybody can not just use the web service except he or she has the secret key, and also, if i could set this on the api side, how do user retrieves this value/secret key on client side and use it while consuming the service.
i have tried this, but not sure whether i am right. below is my code:
public IQueryable<PaymentApi> GetPaymentApi()
{
var re = Request;
var headers = re.Headers;
if(headers.Contains("rtyuiopjhfghjuiopJKLKLJH"))
{
return db.PaymentApi;
}
return null;
}
感谢您的回复。
Thanks for your response.
推荐答案
按照以下链接了解最佳做法。
http://www.soapui.org/testing-dojo/best-practices/understanding-rest-headers-and-parameters.html [ ^ ]
请查看以下链接进行身份验证。还有其他一些方法可以进行身份验证。
RESTful Day#5:Web API中的安全性 - 使用动作过滤器的Web API中的基本身份验证和基于令牌的自定义授权 [ ^ ]
Follow the below link to know the best practices.
http://www.soapui.org/testing-dojo/best-practices/understanding-rest-headers-and-parameters.html[^]
Check the below link for authentication. There are some other ways you can do the authentication.
RESTful Day #5: Security in Web APIs-Basic Authentication and Token based custom Authorization in Web APIs using Action Filters[^]
这篇关于如何在asp.net web api中设置标头值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文