添加角色属性MVC3方法仅在发布模式?属性、角色、模式、方法

2023-09-08 12:50:07 作者:男神综合征

是否有可能增加一个 [授权(角色=管理员)] (作为一个例子)到MVC3控制器的方法,但只有在发行模式?

Is it possible to add an [Authorize(Roles="Admin")] (as an example) to an MVC3 Controller Method but ONLY in Release mode?

在测试环境中我有机会到目前还没有广告,但不活 - 所以我想添加属性只是在释放模式

The Test environment I have access to at the moment has no AD, but Live does - so I'd like to add the attribute only in release mode.

编辑:使用的问题时,#如果

using...
using...
using MyWebsite.Helpers;

namespace MyWebsite.Controllers.Admin
{
#if !DEBUG
    [RedirectAuthorize(Roles = "Admin")]
#endif
    [DatabaseDependant]
    public class AdminController : Controller
    {
      ...
    }

当我加入#如果然后我得到的的错误使用MyWebsite.Helpers; 这样说无法找到(和我的自定义属性[DatabaseDependant]找不到结果)

As soon as I add the #if then I get an error on using MyWebsite.Helpers; saying this cannot be found (and my custom attribute [DatabaseDependant] is not found as a result)

如果我重新编译,然后它......暂时......直到我pretty的编辑很多东西......于是我不得不再次重新编译。

If I recompile, then it works...temporarily...until I pretty much edit anything...whereupon I have to re-compile again.

我缺少一个把戏吗?为什么加入#如果使这种情况发生?

Am I missing a trick here? Why is adding the #if making this happen?

推荐答案

您可以用围绕着它:

#if !DEBUG
[Authorize(Roles="Admin")]
#endif
 
精彩推荐
图片推荐