开发者

Customize IsInRole for ASP.NET application

开发者 https://www.devze.com 2023-01-03 17:33 出处:网络
Can I use IsInRole with customized objects?? Like I want to do some operations only for Employee while other only for Managers.

Can I use IsInRole with customized objects?? Like I want to do some operations only for Employee while other only for Managers.

How can I ach开发者_C百科ieve this?


Make use of the built in features:

This is the way you can to id in a Windows Application

using System.Security.Principal;
... 
var currentUser = WindowsIdentity.GetCurrent();
var winPrincipal = new WindowsPrincipal(currentUser);

if(winPrincipal.IsInRole("Employees")) {
  // TODO: BANANAS
} else if (windPrincipal.IsInRole("Managers")) {
  // TODO: APPLES
}
...

This is the way you can do it in ASP.NET:

if(User.IsInRole("Employees")) {
  // TODO: BANANAS
} else if (User.IsInRole("Managers")) {
  // TODO: APPLES
}

BANANS and APPLES would be what your users get ;-)


Yes you can:

var isMgr = User.IsInRole("Managers");
if(isMgr){
   DoManagerialWork();
}else{
   AccessDenied();
}

but you have to wireup asp.net membership etc. in your (asp.net) application.

0

精彩评论

暂无评论...
验证码 换一张
取 消