简体   繁体   English

ASP.NET Core MVC 6中的AuthorizeAttribute重定向

[英]AuthorizeAttribute redirect in ASP.NET Core MVC 6

What does a function level [Authorize] attribute do when an unauthorized user attempts to access the function? 当未经授权的用户尝试访问功能时,功能级别的[Authorize]属性会做什么? Does the attribute attempt a log-in page redirect? 该属性是否尝试登录页面重定向? Is that information found somewhere? 是否在某处找到该信息? My VS2015 project gets lost in space when the [Authorize] attribute is added. 添加[Authorize]属性后,我的VS2015项目在空间中迷失了。

Make sure that you click on some kind of authentication when creating your Core project. 在创建Core项目时,请确保单击某种身份验证。 I'm guess that you have a "No Authentication" template and put on Authorize attributes on it. 我猜您有一个“无身份验证”模板,并在上面放有Authorize属性。

The white page you're seeing is probably due to the application correctly identifying that you are not logged in / authorized, but doesn't have anything else configured as to what happens next. 您看到的白页可能是由于应用程序正确识别出您尚未登录/未授权,但未对接下来发生的事情进行任何其他配置。

VS身份验证选项

What does a function level [Authorize] attribute do when an unauthorized user attempts to access the function? 当未经授权的用户尝试访问功能时,功能级别的[授权]属性会做什么?

In .Net Core, it will validate a user based off of the policies that it has been given. 在.Net Core中,它将根据提供的策略来验证用户。 It will return a failure if they do not meet them. 如果他们不满足他们,它将返回一个失败。

Does the attribute attempt a log-in page redirect? 该属性是否尝试登录页面重定向?

The Authorize attribute itself doesn't decide what happens when an unauthorized user attempts to access a method. Authorize属性本身无法确定未经授权的用户尝试访问方法时会发生什么情况。

Does the attribute attempt a log-in page redirect? 该属性是否尝试登录页面重定向?

Assuming of course, that we speak about login via Individual User Accounts (read @WillRay comments below): 当然,假设我们谈论通过个人用户帐户登录(请阅读下面的@WillRay评论):

If unauthenticated user try access to page/action decorated witch [Authorise] attribute then is redirected to login page, and after login is redirected back. 如果未经身份验证的用户尝试访问页面/装饰有动作的女巫[Authorise]属性,则将其重定向到登录页面,并在登录后重定向回。

This is how it's work in my case at MVC Core WebApp. 以我为例,在MVC Core WebApp中就是这样工作的。


Is that information found somewhere? 是否在某处找到该信息?

You can find more information here: 您可以在这里找到更多信息:


My VS2015 project gets lost in space when the [Authorize] is added 添加[授权]后,我的VS2015项目在空间中迷失了

This works fine for me - both on RC1 and RC2. 这对我来说很好-在RC1和RC2上都可以。

Looks like somewhere you have wrong configuration. 看起来您配置错误。

Check if you have all required packages and clean up your web.config . 检查是否具有所有必需的软件包,并清理web.config

Or try new/clean project from VS template and check if it's works. 或者尝试从VS模板新建/清除项目,然后检查其是否有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AuthorizeAttribute 在 ASP.NET Core 3 MVC 中什么都不做 - AuthorizeAttribute does nothing in ASP.NET Core 3 MVC 在ASP.NET Core MVC API控制器上单元测试AuthorizeAttribute - Unit testing an AuthorizeAttribute on an ASP.NET Core MVC API controller Web API的AuthorizeAttribute(ASP.NET Core 2) - AuthorizeAttribute for Web API (ASP.NET Core 2) ASP.Net MVC:是否可以覆盖AuthorizeAttribute? - ASP.Net MVC: Can the AuthorizeAttribute be overriden? ASP.Net MVC安全性AuthorizeAttribute - ASP.Net MVC Security AuthorizeAttribute ASP.NET MVC 3中的AuthorizeAttribute和输出缓存 - AuthorizeAttribute and output caching in asp.net mvc 3 从 MVC 迁移到 ASP.NET Core 3.1 中的端点路由时,具有角色的 AuthorizeAttribute 不起作用 - AuthorizeAttribute with Roles not working when migrating from MVC to Endpoint Routing in ASP.NET Core 3.1 如何在ASP.NET Core中添加全局`AuthorizeFilter`或`AuthorizeAttribute`? - How to add global `AuthorizeFilter` or `AuthorizeAttribute` in ASP.NET Core? AuthorizeAttribute 在 ASP.net 核心中返回自定义值(无覆盖) - AuthorizeAttribute return Custom Value in ASP.net Core (Without Override) 如何在 ASP.NET Core 中创建自定义 AuthorizeAttribute? - How do you create a custom AuthorizeAttribute in ASP.NET Core?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM