WebSecurity 属性 -CurrentUserId


WebSecurity オブジェクト

定义

CurrentUserId属性は現在のユーザーのWebSecurityデータベース内のID(主キー)。


C# および VB 構文

WebSecurity.CurrentUserId


实例

实例 C#

@{
int value;
value=WebSecurity.CurrentUserId;
}

<p>Current User ID is: @value</p>

实例 VB

@Code
Dim value as Integer
value=WebSecurity.CurrentUserId
End Code

<p>Current User ID is: @value</p>


备注

CurrentUserId属性は読み取り専用です。コードでは変更できません。

この属性は識別に使用されますWebSecurityデータベースのユーザープロフィールテーブルと会員テーブルのユーザー。


エラーと例外

現在ユーザーがログインしていない場合は、CurrentUserId属性は -1 を返します。

以下の場合、任意のWebSecurityオブジェクトへのアクセスは、例外をスローしますInvalidOperationException:

  • InitializeDatabaseConnection()メソッドは呼び出されていません
  • SimpleMembership初期化されていません(またはサイト設定で無効化されています)。

技术数据

名称 值
Namespace WebMatrix.WebData
Assembly WebMatrix.WebData.dll


WebSecurity オブジェクト 其他扩展