添加角色属性MVC3方法仅在发布模式? [英] Add Role attribute to MVC3 methods only in Release mode?

查看:194
本文介绍了添加角色属性MVC3方法仅在发布模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能增加一个 [授权(角色=管理员)] (作为一个例子)到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

这篇关于添加角色属性MVC3方法仅在发布模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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