Regarding Authorize attribute usage in ASP.Net MVC 4

Thomas

when we decorate any action with Authorize attribute then how MVC redirect to login form because my login controller name could be different and also view name also could be different. login view also could be stored in different folder instead of shared folder.

so tell me how MVC engine understand that it need to load login form when face Authorize attribute ?

how MVC engine would know where login form template is stored because it location could be different instead of shared folder?

how MVC engine would know what is login controller name if my login controller name is different ?

please discuss 3 points i asked here in details. thanks

Sirwan Afifi

The AuthorizeAttribute is a filter, which means that it can execute before the associated controller action. The AuthorizeAttribute performs its main work in the OnAuthorization method. If the user fails authentication, an HttpUnauthorizedResult action result is returned which produced an HTTP 401 status code. In previous versions of ASP.NET MVC the user redirected to the application login page defined in the application's web.config:

<authentication mode="Forms">
    <forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>

In ASP.NET MVC 5, the redirection process is handled by OWIN middleware components. It redirects unauthenticated requests to a LoginPath value, which defaults to "/Account/Login":

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
         AuthenticationType =
         DefaultAuthenticationTypes.ApplicationCookie,
         LoginPath = new PathString("/Account/Login")
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Custom Authorize Attribute on asp.net mvc

ASP .Net MVC 4 Authorize and AllowAnonymous

ASP.NET MVC 4 Custom Authorize Attribute with Permission Codes (without roles)

Asp.net Core MVC Authorize Attribute not blocking

Authorize with a specific scheme in ASP.NET MVC 4

Asp.Net MVC 4 - ActionFilterAttribute Usage

Authorize in ASP mvc4

How to create a custom attribute that will redirect to Login if it returns false, similar to the Authorize attribute - ASP.NET MVC

Authorize attribute on entire project in .net mvc for security

ASP.Net MVC Action Filter : What is the difference between OnActionExecuting and OnResultExecuting regarding usage

Custom Authorize Attribute not working asp.net

Custom Authorize attribute - ASP .NET Core 2.2

How [Authorize] attribute get to know that the user is authenticate in ASP.NET MVC, is it by using authentication token?

Using Asp.Net Core Identity in MVC, Authorize attribute is rebouncing to login page after succesfull login

ASP.Net MVC 5 how to use Authorize Attribute with multiple login (Multiple user table)

ASP.NET MVC 4 Custom Authorize filter on Controller class and Method

Multiple remote validation attribute in ASP.NET MVC4

Mvc Authorize attribute is not working

How to create a Custom Authorize Attribute by comparing User Id stored in table with Current User Id in Asp.net MVC 5?

ASP.NET MVC 5 Azure Website fails to connect to SQL Azure DB on some views due to role based [Authorize] attribute

Does anyone have a good explanation on how the [Authorize] Attribute handles routes in a standard ASP.NET MVC 5 application?

Redirect loop with .Net MVC Authorize attribute with ADFS Claims

Roles in Authorize Attribute does not work as expected in MVC 4

Capture exceptions from Authorize attribute in MVC4

ASP.NET Core 3 API Ignores Authorize Attribute with Bearertoken

Return HTTP 403 using Authorize attribute in ASP.Net Core

What is the default behavior of violating the Authorize attribute in ASP.NET Core

Using the Authorize Attribute with Custom Cookie Authentication in ASP.NET Core

ASP.NET Core Authorize attribute not working with JWT