Click here to Skip to main content
15,891,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:



C#
public IQueryable<PaymentApi> GetPaymentApi()
       {
           var re = Request;
           var headers = re.Headers;
           if(headers.Contains("rtyuiopjhfghjuiopJKLKLJH"))
           {
               return db.PaymentApi;
           }
           return null;
       }


Thanks for your response.
Posted
Updated 20-Sep-15 5:42am
v2

1 solution

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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900