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

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

RoleProvider.RoleExists メソッド

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

指定されたロール名が、構成済みの applicationName のロール データ ソースに既に存在するかどうかを示す値を取得します。

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

Public MustOverride Function
 RoleExists ( _
    roleName As String _
) As Boolean
Dim instance As RoleProvider
Dim roleName As String
Dim returnValue As Boolean

returnValue = instance.RoleExists(roleName)
public abstract bool RoleExists (
    string roleName
)
public:
virtual bool RoleExists (
    String^ roleName
) abstract
public abstract boolean RoleExists (
    String roleName
)
public abstract function RoleExists (
    roleName : String
) : boolean

パラメータ

roleName

データ ソースで検索するロールの名前。

戻り値
ロール名が構成済みの applicationName のデータ ソースに既に存在する場合は true。それ以外の場合は false。

解説解説

RoleExists は Roles クラスの RoleExists メソッドによって呼び出され、ロール名が構成済みの ApplicationName のデータ ソースに存在しているかどうかを判断します。

指定された roleName が null 参照 (Visual Basic では Nothing) または空の文字列である場合、プロバイダから例外をスローすることをお勧めします。

使用例使用例

RoleExists メソッドの実装サンプルを次のコード例に示します。

Public Overrides Function
 RoleExists(rolename As String) As
 Boolean 

  If rolename Is Nothing
 OrElse rolename = "" Then
 _
    Throw New ProviderException("Role
 name cannot be empty or null.")

  Dim exists As Boolean
 = False

  Dim conn As OdbcConnection = New
 OdbcConnection(connectionString)
  Dim cmd As OdbcCommand = New
 OdbcCommand("SELECT COUNT(*) FROM [" & rolesTable
 & "]" & _
                                           " WHERE Rolename =
 ? AND ApplicationName = ?", conn)

  cmd.Parameters.Add("@Rolename", OdbcType.VarChar,
 255).Value = rolename
  cmd.Parameters.Add("@ApplicationName", OdbcType.VarChar,
 255).Value = ApplicationName

  Try
    conn.Open()

    Dim numRecs As Integer
 = CType(cmd.ExecuteScalar(), Integer)

    If numRecs > 0 Then
      exists = True
    End If
  Catch e As OdbcException
    ' Handle exception.
  Finally
    conn.Close()      
  End Try

  Return exists
End Function
public override bool RoleExists(string
 rolename)
{
  if (rolename == null || rolename == "")
    throw new ProviderException("Role name cannot be empty
 or null.");

  bool exists = false;

  OdbcConnection conn = new OdbcConnection(connectionString);
  OdbcCommand cmd = new OdbcCommand("SELECT COUNT(*) FROM
 [" + rolesTable + "]"  +
                                    " WHERE Rolename = ? AND ApplicationName
 = ?", conn);

  cmd.Parameters.Add("@Rolename", OdbcType.VarChar, 255).Value = rolename;
  cmd.Parameters.Add("@ApplicationName", OdbcType.VarChar, 255).Value =
 ApplicationName;

  try
  {
    conn.Open();

    int numRecs = (int)cmd.ExecuteScalar();

    if (numRecs > 0)
    {
      exists = true;
    }
  }
  catch (OdbcException)
  {
    // Handle exception.
  }
  finally
  {
    conn.Close();      
  }

  return exists;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

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

   

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



RoleProvider.RoleExists メソッドのページの著作権

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

©2026 GRAS Group, Inc.RSS