- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一堆 Controller 在类级范围内具有 [AllowAnonymous] 属性。在执行此类 Controller 中的任何操作之前,我需要检查一些事项。例如,我可能会这样做:
[AllowAnonymous]
public class MyController : Controller
{
[HttpGet]
public ActionResult Index()
{
// do some preliminary work
// run action-specific code
}
}
因为我有很多这样的 Controller 和 Action ,复制粘贴相同的代码是一个乏味的过程。有没有办法以更简单的方式为每个匿名操作执行此初步代码?
最佳答案
您可以创建自己的操作过滤器。
创建一个继承ActionFilterAttribute
并覆盖OnActionExecuting
的类。
将该属性应用于 Controller 或操作,它将在对该 Controller 或操作的每个请求之前运行。
关于asp.net-mvc - 在使用 [AllowAnonymous] 执行 Controller 中的 MVC 操作之前运行代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12885301/
我在我的 asp.net web api 中设置了一个客户授权属性 全局文件: FilterConfig.RegisterHttpFilters(GlobalConfiguration.Confi
一切正常,直到我安装(包管理器控制台)邮政包,然后卸载并安装旧版本。 现在我得到了一个以前没有的错误。错误: 找不到类型或命名空间名称“AllowAnonymous”(是否缺少 using 指令或程序
AllowAnonymous 和OverrideAuthorizeAttribute 的使用有什么区别。一样吗? 最佳答案 http://www.asp.net/web-api/overview/se
我想了解 [AllowAnonymous] 标签的工作原理。 我有以下方法 [HttpGet] public ActionResult Add() { return View(); } 当我没
我正在使用自定义过滤器(定义如下): if (user == null || !user.Active) { filterContext.Res
我试图阻止特定角色(比如 RoleA)中的特定用户访问特定操作。允许匿名用户访问,但不允许 RoleA 中的用户访问该操作。 所以我做了这样的事情: [AllowAnonymous] [CustomA
我正在尝试为我的服务器设置自己的自定义身份验证。但是它会为每个端点调用,即使它在方法上具有 [AllowAnonymous] 属性也是如此。使用我当前的代码,我每次都可以在 HandleAuthent
我有一个 CustomApiAuthorizeAttribute: public class CustomApiAuthorizeAttribute : AuthorizeAttribute {
我已经创建了一个 Blazor WebAssembly 项目,并希望提供一个具有一个公共(public)可用函数的 WebAPI。 [Route("api/[controller]")] [ApiCo
我有一个建立在 Umbraco 上的整个网站,需要限制对所有页面的访问。唯一的异常(exception)是登陆页面和注销确认页面。 要将访问限制为仅登录用户,我在 web.config 中有以下内容:
使用 .Net 框架,Web Api。 我的 Controller 上有 [Authorize] 属性,某些端点上有 [AllowAnonymous]。 我有几个允许匿名的端点,但如果用户通过身份验证
当我应用这段代码时授权 Controller 方法和 AllowAnonymous在里面的一种操作方法上,所有操作方法都将被授权,除了上面有 AllowAnonymous 元数据的方法。显然,操作方法
我有一个 Asp.net MVC 应用程序,我在其中使用 Azure AD 身份验证对用户进行身份验证。我想允许用户在不登录的情况下访问一些 api Controller 。我尝试将 [AllowAn
在我的 .NET MVC 4 中,我添加了一个全局过滤器以保护我的 Controller 。 这是使用以下方法完成的: public static void RegisterGlobalFilters
这让我困惑了一段时间。显然,常见的类似情况似乎都不适用。我可能错过了一些明显的东西,但我看不到它。 在我的 Mvc Web 应用程序中,我使用 Authorize 和 AllowAnonymous 属
我有两个 MVC 5 应用程序,据我所知,它们都是相同的(一个是从另一个创建的)。然而,其中一个 AllowAnonymous 不起作用。 如果我在 FilterConfig 中注册 filters.
我正在使用 Web API Controller 构建 Web 服务。但是,当我尝试使用 [allowanonymous] 属性装饰我的任何操作时,它不起作用......这是一张图片 我只是想知道这里
当我创建一个新的 asp.net mvc 4.0 应用程序时,我做的第一件事 就是创建并设置自定义授权全局过滤器,如下所示: //FilterConfig.cs public static void
我通过继承 DelegatingHandler 实现了基于 JWT 的身份验证并将类添加为 configuration.MessageHandlers.Add(new MyDelegatingHand
我想使用 AllowAnonymous 和自定义 AuthenticationFilter。有人可以指出我使用 AllowAnonymous 或其他替代方法的正确方向吗?谢谢 我创建了自己的自定义过滤
我是一名优秀的程序员,十分优秀!