管理者が教師と生徒を追加できるウェブサイトを作成しているので、管理者は教師が特定の場所にいるときにできることを指定する必要があります。MVC3余分な役割の属性
Authorize属性を拡張して、特定のユーザーの場所を確認することはできますか?たとえば、[Authorize(Roles = "Administrator"、Location = "ICT")]?
もしそうなら、これをどのように延長できますか?
ありがとうございます。
管理者が教師と生徒を追加できるウェブサイトを作成しているので、管理者は教師が特定の場所にいるときにできることを指定する必要があります。MVC3余分な役割の属性
Authorize属性を拡張して、特定のユーザーの場所を確認することはできますか?たとえば、[Authorize(Roles = "Administrator"、Location = "ICT")]?
もしそうなら、これをどのように延長できますか?
ありがとうございます。
もしそうなら、これをどのように延長できますか?カスタム属性を承認書き込むことにより
:
public class MyAuthorizeAttribute : AuthorizeAttribute
{
public string Location { get; set; }
protected override bool AuthorizeCore(System.Web.HttpContextBase httpContext)
{
var result = base.AuthorizeCore(httpContext);
if (!result)
{
return false;
}
// At this stage we know that the currently logged in user
// is authorized. Now you could use the Location property
// to perform additional custom authorization checks and
// return true or false from here
string user = httpContext.User.Identity.Name;
...
}
}
、その後:
[MyAuthorize(Roles = "Administrator", Location = "ICT")]
独自のカスタムAUTHORIZE属性を作成することができます。 ビデオを見るasp-net-mvc3-custom-membership-authorizeattribute-tutorial
こんにちはダリン、どこにこのクラスを置くのですか? –
@StewieFG、どこでも好きです。あなたのASP.NET MVCアプリケーションは良い場所です。カスタム許可属性などを整理するためのサブフォルダを作成することができます。 –
ありがとうダーリン –