System.Web.Http.Authorize与System.Web.Mvc.Authorize [英] System.Web.Http.Authorize versus System.Web.Mvc.Authorize

查看:151
本文介绍了System.Web.Http.Authorize与System.Web.Mvc.Authorize的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有授权属性?结果
System.Web.Http.Authorize结果
System.Web.Mvc.Authorize

using System.Web.Mvc      // or
using System.Web.Http  

一个典型的控制器

    [Authorize]
    public class SomeController : Controller

我们有注释控制器[授权]
我只是注意到,由于使用命名空间注释技术上是指不同的属性类。

We have controllers Annotated with [Authorize] I just noticed that due to using namespaces the annotations technically refer to different attribute classes.

该项目包含MVC控制器和的WebAPI控制器。

The project contains MVC controllers and WEBAPI controllers.

哪一个我应该使用,为什么?
我们可能有什么问题,如果我不解决这个问题?

Which one should I use and why ? What issues might we have if I dont fix this ?

推荐答案

您必须使用 System.Web.Http.Authorize 针对 ApiController (API网络控制器)和 System.Web.Mvc.Authorize 针对控制器(MVC控制器)。由于框架运行过滤器作为流水线处理的一部分,控制器期望应用适当的过滤器,如果你不使用相应的过滤器,授权将无法工作。

You must use System.Web.Http.Authorize against an ApiController (Web API controller) and System.Web.Mvc.Authorize against a Controller (MVC controller). Since the framework runs the filters as part of the pipeline processing and the controllers expect the right filter to be applied, if you don't use the corresponding filter, authorization will not work.

这篇关于System.Web.Http.Authorize与System.Web.Mvc.Authorize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆