WebService.User 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取 ASP.NET 服务器 User 对象。 可用于验证用户是否有权执行请求。
public:
property System::Security::Principal::IPrincipal ^ User { System::Security::Principal::IPrincipal ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Security.Principal.IPrincipal User { get; }
[<System.ComponentModel.Browsable(false)>]
member this.User : System.Security.Principal.IPrincipal
Public ReadOnly Property User As IPrincipal
属性值
表示 IPrincipal ASP.NET 服务器 User 对象。
- 属性
示例
下面的示例查找经过身份验证的用户名并返回该名称。
<%@ WebService Language="C#" Class="Util" %>
using System.Web.Services;
public class Util: WebService {
[ WebMethod(Description="Obtains the User Name",EnableSession=false) ]
public string GetUserName() {
return User.Identity.Name;
}
}
<%@ WebService Language="VB" Class="Util" %>
Imports System.Web.Services
Public Class Util
Inherits WebService
<WebMethod(Description := "Obtains the User Name", _
EnableSession := False)> _
Public Function GetUserName() As String
Return User.Identity.Name
End Function
End Class
注解
需要配置 Internet Information Services (IIS) 和 .NET Framework 进行身份验证,以使 User 属性有意义。 身份验证是接受用户凭据并针对某些机构验证这些凭据的过程。 如果凭据有效,则具有经过身份验证的标识。 .NET Framework 中的身份验证是通过将条目放置在 web.config 文件中配置的。
以下示例演示了在 web.config 文件中放置的条目,以启用 Windows 身份验证。
<security>
<authentication mode="Windows"> <!-- Mode Options are Windows, Cookie, Passport and None or Empty String -->
</authentication>
</security>
有关设置 XML Web 服务安全性的详细信息,请参阅 保护使用 ASP.NET 创建的 XML Web 服务。