I’ve been tested a Web API web service and I needed an anonymous authentication. This can be done with attribute [AllowAnonymous].
You can decorate a whole controller
1 2 3 |
[AllowAnonymous] public class PersonController : ApiController { |
or a particular method(s)
1 2 3 4 5 |
[HttpGet] [AllowAnonymous] [Route("api/Person/Find")] public PersonData Find(string code) { |
The most curious thing is that it does not work when you run Visual Studio debugger! The secret is hidden in the properties of the Web API project. Click the project in Solution Explorer, then press F4 (don’t choose Properties from context menu). Here you will see authentication settings.
All these properties are saved in .csproj file.
1 2 3 4 5 6 7 8 9 |
<Project ToolsVersion="12.0" ... <Import Project=... <PropertyGroup> ... <UseIISExpress>true</UseIISExpress> <IISExpressSSLPort /> <IISExpressAnonymousAuthentication>disabled</IISExpressAnonymousAuthentication> <IISExpressWindowsAuthentication>enabled</IISExpressWindowsAuthentication> ... |