Custom authorization using WEB API
-
03-06-2021 - |
Question
I've implmented an service using MVC WEB API and i implemented a custom way to authenticate the requests. this is how it looks like:
public HttpResponseMessage GetTest()
{
try
{
IDBModel DAO = new DBModelDAO();
if (DAO.IsApiKeyValid(Request.Headers.Authorization.Parameter))
{
return new HttpResponseMessage(HttpStatusCode.OK);
}
}
catch (Exception e)
{
System.Diagnostics.Trace.WriteLine(e.Message);
}
return new HttpResponseMessage(HttpStatusCode.Unauthorized);
}
However if the authentication fails i get redirected to this uri: /Account/Login?ReturnUrl=%2ftest
And i don't want that because i don't use the webbrowser for authenticating.
How can i disable this feature?
Your help is very much appreciated!
Zoli
Solution
The part:
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
has to be commented and it won't redirect
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow