English 中文(简体)
ASP.NET /MVC. 用于检查角色的网络标签(相当于申报性属性)
原标题:ASP.NET / MVC.NET tag for checking roles (equivalent of declarative attribute PrincipalPermission)

我在我的多指标类集调查中使用宣示作用。 NET控制器和我拥有一个定制会员和办公室;角色提供商。

罚款:

 [Authorize(Roles = "ADMIN")]

此外,我有一个MVC基地。 NET 海关主计长级称,所有控制人员都来自并拥有“现值User”财产,这些财产按要求从届会自动上列,因此所有控制人员代码都只提及“现值User”,并对会议、httpcontext等表示担忧。 我先妥善执行会员提供人,因为它与框架中与供应商打交道的其他部分合作,但直到现在,我一直没有试图从某种角度接触“User”主人。

什么是观察页面中最简单的检查作用? 我知道,我可以利用助手来产生一种部分看法,但我不想在这里明确总结一下某些角色检查中页的某些部分。

与此类似:

<% if(currentUser.IsInRole("ADMIN") { %>
...
<% } %>

感谢。

最佳回答

最简单的方式是准确做你正在做的事情,在这种背景下检查目前的用户。 您可查阅目前<代码>User的主版。 通过《意见书》,<代码>。

var currentUser = this.ViewContext.HttpContext.User;
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签