首页
WP 参考手册

分类

当前位置: 天天编程网 > ASP.NET > 正文

CurrentUserId[asp.net WebSecurity 对象]

更新时间:2023-11-27   来源:天天编程网

定义

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
更多学习推荐
小编推荐
快速导航更多>>
JavaScript 教程 HTML5 教程 CSS3 教程 jQuery 教程 Vue.js 教程 Node.js 教程 SQL 教程 C 教程 PHP 教程 Linux 教程 Docker 教程 Nginx 教程 Python 教程 Java 教程

天天编程网 版权所有

陕ICP备2023002928号-1