WebSecurity CurrentUserId 屬性
定義
CurrentUserId屬性是當前用戶在WebSecurity數據庫中的ID(主鍵)。
C# 和VB 語法
WebSecurity.CurrentUserId
實例
實例C#
@{
int value;
value=WebSecurity.CurrentUserId;
}
<p>Current User ID is: @value</p>
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>
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對象