ASP.NET MVC3でWindows認証を使用してカスタムロールベースの許可を使用する方法

StackOverflow https://stackoverflow.com/questions/9032451

質問

Windows認証を備えたASP.NET MVC3イントラネットアプリケーションを作成しています。私はドメインユーザーがこのアプリケーションを使用するだけです。ドメインユーザーが認証されると( Active Directory で)、承認のSQL Server内のユーザーの作成(adusername)、Roles&Userrolesテーブルを作成することを計画しています。

SOユーザーが、(コントローラ/アクションにアクセスするための)許可のセットを持つ役割の一部である場合は、その役割のユーザーがそれらを実行/表示することを許可する必要があります。 例:アクション/場所/作成/作成がある場合は、それを実行することを許可されているロールはそれを実行できます。

誰かが私にいくつかのポインタを与えることができますか?カスタムアクションフィルタを作成し、フィルタを適用したい任意のアクションメソッドにフィルタ属性を使用する必要がありますか?

役に立ちましたか?

解決

To restrict access to an ASP.NET MVC view, you restrict access to the action method that renders the view. To accomplish this, the MVC framework provides the AuthorizeAttribute class.

Example:

[Authorize(Roles = "Admin, Super User")]
public ActionResult AdministratorsOnly()
{
 return View();
}

See here for more details.

Note that using the [Authorize] attribute requires you to use some sort of Membership provider.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top