Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I have a web application using ASP .NET MVC. In this application there is a WEB API. Which will return some JSon data. I have added BASIC authentication code for this WEB API and is working fine in my local. I Tried it with POST MAN. Now I hosted the site in IIS. After hosting I enabled BASIC authentication in SERVER. There is no error in code and is working fine in local. When ever I try to call this service I am getting "401 - Unauthorized: Access is denied due to invalid credentials." error and I can access other pages of the site with out any issue. My requirement is , I need to enable BASIC authentication for this api only not for the whole application. Is that possible? If possible could any one please help me.

Thank you

What I have tried:

I have enabled BASIC Authentication in server. But it enables authentication for whole application and getting "401 - Unauthorized: Access is denied due to invalid credentials." error when i try to access the service. I need authentication for this particular service only.
Posted
Updated 15-May-18 2:07am

1 solution

Haven't had a need in WebAPI yet, but in earlier Asp.Net/MVC you could drop a WebConfig file in any of the View directories which could be used to enforce the Basic Authentication.

The work I am doing now we add an authorization header into the request collection and check that within the method calls.
To get the correct values we have a Login method to validate credentials and return the correct token for usage
 
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