I have a Web API application with MVC. When a user uses a website, authentication and authorization are now automatically handled by the global form authentication that I use, configured in Web.config as follows:
<authentication mode="Forms">
<forms loginUrl="~/Login" slidingExpiration="true" timeout="1800" defaultUrl="/"></forms>
</authentication>
<authorization>
<deny users="?" />
</authorization>
This ensures that only registered users can access the site and call the API.
But I also have an external Windows client for which I would like to use a different authentication method. In a test without auth forms, I set up a custom attribute, AuthorizeAttribute, which I can use in my controllers, for example:
[ApiAuth]
public IEnumerable<string> Get() {
}
An authorized attribute looks something like this:
public class ApiAuthAttribute : AuthorizeAttribute {
public override void OnAuthorization(HttpActionContext context) {
}
}
, , auth. , ApiAuth , auth ( , ), [ApiAuth], , api.
, auth, , , , Windows API - , MVC, API ?
.
: , , , Windows auth (- this), , - .