AuthorizationStoreRoleProvider.IsUserInRole メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > AuthorizationStoreRoleProvider.IsUserInRole メソッドの意味・解説 

AuthorizationStoreRoleProvider.IsUserInRole メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

指定されユーザーが、指定されロール存在するかどうかを示す値を取得します

名前空間: System.Web.Security
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Overrides Function
 IsUserInRole ( _
    username As String, _
    roleName As String _
) As Boolean
Dim instance As AuthorizationStoreRoleProvider
Dim username As String
Dim roleName As String
Dim returnValue As Boolean

returnValue = instance.IsUserInRole(username, roleName)
public override bool IsUserInRole (
    string username,
    string roleName
)
public:
virtual bool IsUserInRole (
    String^ username, 
    String^ roleName
) override
public boolean IsUserInRole (
    String username, 
    String roleName
)
public override function IsUserInRole (
    username : String, 
    roleName : String
) : boolean

パラメータ

username

検索するユーザー名

roleName

検索範囲とするロール

戻り値
指定されユーザー名指定されロール存在する場合trueそれ以外場合false

例外例外
例外種類条件

ArgumentNullException

usernamenull 参照 (Visual Basic では Nothing) です。

または

roleNamenull 参照 (Visual Basic では Nothing) です。

ArgumentException

roleName空の文字列です。

または

roleNameコンマ含まれています。

または

usernameコンマ含まれています。

ProviderException

構成済みapplicationName が見つかりませんでした

または

構成済みscopeName が見つかりませんでした

または

承認マネージャ ランタイムサーバーインストールされていません。

FileNotFoundException

connectionStringName 属性が、存在しないファイルへの接続文字列参照してます。

HttpException

AuthorizationStoreRoleProvider インスタンスが、ファイル ベースポリシー ストア使用するように構成されていますが、そのポリシー ファイルへの読み込みアクセス現在の信頼レベル許可されていません。

解説解説
使用例使用例

ログオンしているユーザーユーザー ロール参照許可する前にユーザーが Administrators ロール属しているかどうかプログラムチェックするコード例次に示しますロール管理有効にする Web.config ファイルの例については、AuthorizationStoreRoleProviderトピック参照してください

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Security"
 %>
<script runat="server">

Dim rolesArray() As String
Dim users As MembershipUserCollection

Public Sub Page_Load()

  Msg.Text = ""

  Try
    If Not Roles.IsUserInRole(User.Identity.Name,
 "Administrators") Then
      Msg.Text = "You are not authorized to view user roles."
      UsersListBox.Visible = False
      Return
    End If
  Catch e As HttpException
    Msg.Text = "There is no current logged on user. Role membership
 cannot be verified."
    Return
  End Try


  If Not IsPostBack Then
    ' Bind users to ListBox.

    users = Membership.GetAllUsers()
    UsersListBox.DataSource = users
    UsersListBox.DataBind()
  End If


  ' If a user is selected, show the roles for the selected user.

  If Not UsersListBox.SelectedItem Is
 Nothing Then
    ' Bind roles to GridView.

    rolesArray = Roles.GetRolesForUser(UsersListBox.SelectedItem.Value)
    UserRolesGrid.DataSource = rolesArray
    UserRolesGrid.DataBind()

    UserRolesGrid.Columns(0).HeaderText = "Roles for "
 & UsersListBox.SelectedItem.Value
  End If

End Sub

</script>
<html>
<head>
<title>Sample: View User Roles</title>
</head>
<body>

<form runat="server" id="PageForm">

  <h3>View User Roles</h3>

  <asp:Label id="Msg" ForeColor="maroon"
 runat="server" /><BR>

  <table border="0" cellspacing="4">
    <tr>
      <td valign="top"><asp:ListBox id="UsersListBox"
 DataTextField="Username" 
                                    Rows="8" AutoPostBack="true"
 runat="server" /></td>
      <td valign="top"><asp:GridView runat="server"
 CellPadding="4" id="UserRolesGrid"
 
                                     AutoGenerateColumns="false"
 Gridlines="None" 
                                     CellSpacing="0"
 >
                         <HeaderStyle BackColor="navy"
 ForeColor="white" />
                         <Columns>
                           <asp:TemplateField HeaderText="Roles"
 runat="server" >
                             <ItemTemplate>
                               <%# Container.DataItem.ToString() %>
                             </ItemTemplate>
                           </asp:TemplateField>
                         </Columns>
                       </asp:GridView></td>
    </tr>
  </table>

</form>

</body>
</html>
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<script runat="server">

string[] rolesArray;
MembershipUserCollection users;

public void Page_Load()
{
  Msg.Text = "";

  try
  {
    if (!Roles.IsUserInRole(User.Identity.Name, "Administrators"))
    {
      Msg.Text = "You are not authorized to view user roles.";
      UsersListBox.Visible = false;
      return;
    }
  }
  catch (HttpException e)
  {
    Msg.Text = "There is no current logged on user. Role membership cannot be
 verified.";
    return;
  }


  if (!IsPostBack)
  {
    // Bind users to ListBox.

    users = Membership.GetAllUsers();
    UsersListBox.DataSource = users;
    UsersListBox.DataBind();
  }


  // If a user is selected, show the roles for the selected user.

  if (UsersListBox.SelectedItem != null)
  {
    // Bind roles to GridView.

    rolesArray = Roles.GetRolesForUser(UsersListBox.SelectedItem.Value);
    UserRolesGrid.DataSource = rolesArray;
    UserRolesGrid.DataBind();

    UserRolesGrid.Columns[0].HeaderText = "Roles for "
 + UsersListBox.SelectedItem.Value;
  }
}

</script>
<html>
<head>
<title>Sample: View User Roles</title>
</head>
<body>

<form runat="server" id="PageForm">

  <h3>View User Roles</h3>

  <asp:Label id="Msg" ForeColor="maroon" runat="server"
 /><BR>

  <table border="0" cellspacing="4">
    <tr>
      <td valign="top"><asp:ListBox id="UsersListBox"
 DataTextField="Username" 
                                    Rows="8" AutoPostBack="true"
 runat="server" /></td>
      <td valign="top"><asp:GridView runat="server"
 CellPadding="4" id="UserRolesGrid" 
                                     AutoGenerateColumns="false"
 Gridlines="None" 
                                     CellSpacing="0" >
                         <HeaderStyle BackColor="navy" ForeColor="white"
 />
                         <Columns>
                           <asp:TemplateField HeaderText="Roles" runat="server"
 >
                             <ItemTemplate>
                               <%# Container.DataItem.ToString() %>
                             </ItemTemplate>
                           </asp:TemplateField>
                         </Columns>
                       </asp:GridView></td>
    </tr>
  </table>

</form>

</body>
</html>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
AuthorizationStoreRoleProvider クラス
AuthorizationStoreRoleProvider メンバ
System.Web.Security 名前空間
その他の技術情報
ロール管理について


このページでは「.NET Framework クラス ライブラリ リファレンス」からAuthorizationStoreRoleProvider.IsUserInRole メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からAuthorizationStoreRoleProvider.IsUserInRole メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からAuthorizationStoreRoleProvider.IsUserInRole メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

AuthorizationStoreRoleProvider.IsUserInRole メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



AuthorizationStoreRoleProvider.IsUserInRole メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS