Sys.Services.RoleService クラス
更新 : 2007 年 11 月
ASP.NET ロール サービスのクライアント プロキシ クラスを提供します。
名前空間 :Sys.Services
メンバ
名前 |
説明 |
---|---|
既定のロール サービスへのパスを指定します。 |
|
RoleService クラスの新しいインスタンスを初期化します。 |
|
現在認証されているユーザーのロールを読み込みます。 |
|
既定の失敗コールバック関数の名前を取得または設定します。 |
|
Sys.Services の RoleService の defaultLoadCompletedCallback プロパティ |
既定の読み込み完了コールバック関数の名前を取得または設定します。 |
サービスの既定の成功コールバック関数を取得または設定します。 |
|
サービスの既定のユーザー コンテキストを取得または設定します。 |
|
現在認証されているユーザーが指定されたロールになっているかどうかをチェックします。 |
|
ロール サービス パスを取得または設定します。 |
|
現在認証されているユーザーのロールを取得します。 |
|
ロール サービスのタイムアウト値を取得または設定します。 |
解説
RoleService クラスは、現在認証されているユーザーのロール情報へのスクリプト アクセスを提供します。このクラスは、ロール サービスのメソッドを、他の Web サービス メソッドを呼び出す場合と同じインフラストラクチャを介して呼び出します。Web ロール サービスは、インスタンスを 1 つしか持たないクラス (シングルトン) として実装されます。RoleService プロキシ クラスを介してアプリケーションでいつでも使用でき、インスタンス化する必要はありません。
例
説明
RoleService クラスを使用して、現在認証されているユーザーのロールを取得する方法の例を次に示します。詳細については、「ASP.NET AJAX でのロール情報の使用」を参照してください。
コード
var roleProxy;
var roles;
// This function creates the role proxy and
// sets its default callback functions.
function pageLoad()
{
// Create role service proxy.
roleProxy = Sys.Services.RoleService;
// Set the default failed callback function.
DefaultFailedCallBack();
// Set the default load completed callback function.
DefaultLoadCompletedCallBack()
}
// This function sets and gets the role service
// default failed callback function.
function DefaultFailedCallBack()
{
// Set default failed callback function.
roleProxy.set_defaultFailedCallback(FailedCallback);
// Get the default callback function.
var failedCallBack =
roleProxy.get_defaultFailedCallback();
alert(failedCallBack);
}
// This function sets and gets the role service
// default load completed callback function.
function DefaultLoadCompletedCallBack()
{
// Set the default callback function.
roleProxy.set_defaultLoadCompletedCallback(LoadCompletedCallback);
// Get the default callback function.
var loadCompletedCallBack =
roleProxy.get_defaultLoadCompletedCallback();
alert(loadCompletedCallBack);
}
// This function checks if the currently
// authenticated user belongs to the
// passed role.
function UserIsInRole(role)
{
DisplayInformation("");
var isUserInRole = roleProxy.isUserInRole(role);
DisplayInformation("The user is in the " + role +
" role: " + isUserInRole);
}
// This function gets the role service path.
function GetRoleServicePath()
{
// Get the role service path.
var roleServicePath =
Sys.Services.RoleService.get_path();
if (roleServicePath == "")
{
DisplayInformation(
"The role service path is the default value.");
}
}
// This function gets the roles of the
// currently authenticated user.
function ReadUserRoles()
{
// Clear the feedback output.
DisplayInformation("");
// You must load the user's roles
// first before you can use them.
roleProxy.load();
// Read the user's roles.
roles = roleProxy.get_roles();
}
// This function gets the role service timeout.
function GetRoleServiceTimeout()
{
// Get the role service path.
var roleServiceTimeout =
Sys.Services.RoleService.get_timeout();
DisplayInformation(
"Role service timeout: " + roleServiceTimeout);
}
// This is the callback function
// called if the role service load function
// completed.
function LoadCompletedCallback(roles)
{
// Read the user's roles loaded
// before.
roles.sort();
for(var i = 0; i < roles.length; i++)
{
var roleInfo = "Role: " + roles[i];
DisplayInformation(roleInfo);
}
}
// This is the callback function
// called if the role service fails.
function FailedCallback(error)
{
DisplayInformation("Error: " + error.get_message());
}
// This function displays user's
// feedback information.
function DisplayInformation(text)
{
document.getElementById('placeHolder').innerHTML =
"<br/>"+ text;
}
if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
参照
概念
Sys.Services.AuthenticationService クラス