c# - Authentication In MVC & WebAPI Website -
I have a website that has simple form authentication, the credentials are valid with the database. It's fine as it is. My & lt; web.config within System.web & gt;
I have:
& lt; Authentication mode = "form" & gt; & Lt; Forms loginUrl = "~ / account / login" timeout = "2880" /> & Lt; / Authentication & gt;
I need to add a small WebAP controller to the site for an app to drag a list of objects. It seems, as far as WebApi authentication goes, the original authentication will be fine. I will have user credentials in the application, which can easily pass, request encoded in the header.
My problem is differentiating between MVC and WebApi authentication. First of all, is my solution a good idea, and implemented smoothly? Currently, I have my WebApiConfig.cs
in:
Global Configuration. Configuration. Message Holders Add (New BasicAuthenticationHandler (New Authentication Service)); Looks for credentials in
and BasicAuthenticationHandler
headers. However, with MVC forms authentication, I am unable to reach that area. When I acted in intelligence, I can see that it redirects directly to the MVC account / login page. How to Avoid Redirecting My WebAPI Call?
Thanks for any guidance.
OK, it seems that this was a simple improvement. The direct line above the web.config code is appearing on me:
& lt; Authentication mode = "form" & gt; & Lt; Forms loginUrl = "~ / account / login" timeout = "2880" /> & Lt; / Authentication & gt; & Lt; Authority & gt; & Lt; Deny users = "?" / & Gt; & Lt; / Authorization & gt;
And it looks like the authorization
element was written entirely on any [AllowAnonymous]
- anonymously The only possible way to access was by removing those 3 lines of login page and fixing my problem - I now use the [AllowAnonymous]
attribute for my webpage page, and this basic authentication Applies correctly
Comments
Post a Comment