WebService.User WebService.User WebService.User WebService.User Property

定义

获取 ASP.NET 服务器 User 对象。Gets the ASP.NET server User object. 可用于验证用户是否有权执行请求。Can be used to authenticate whether a user is authorized to execute the request.

public:
 property System::Security::Principal::IPrincipal ^ User { System::Security::Principal::IPrincipal ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Security.Principal.IPrincipal User { get; }
member this.User : System.Security.Principal.IPrincipal
Public ReadOnly Property User As IPrincipal

属性值

代表 ASP.NET 服务器 IPrincipal 对象的 UserA IPrincipal representing the ASP.NET server User object.

示例

下面的示例查找经过身份验证的用户名并返回该名称。The example below looks up the authenticated user name and returns that name.

<%@ 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配置, 以便属性有意义。Both Internet Information Services (IIS) and the .NET Framework need to be configured for authentication in order for the User property to be meaningful. 身份验证是接受来自用户的凭据并针对某些颁发机构验证这些凭据的过程。Authentication is the process of accepting credentials from a user and validating those credentials against some authority. 如果凭据有效, 则您有一个经过身份验证的标识。If the credentials are valid, you have an authenticated identity. .NET Framework 中的身份验证通过将条目放入 web.config 文件来进行配置。Authentication in the .NET Framework is configured by placing entries in the web.config file.

下面的示例演示在 web.config 文件中放置的项, 以启用 Windows 身份验证。The following example demonstrates the entries you place in the web.config file to enable Windows authentication.

<security>  
 <authentication mode="Windows"> <!-- Mode Options are Windows, Cookie, Passport and None or Empty String -->  
 </authentication>  
 </security>  

有关设置 XML Web service 安全性的详细信息, 请参阅保护使用 ASP.NET 创建的 XML Web ServicesFor more information on setting up security for an XML Web service see Securing XML Web Services Created Using ASP.NET.

适用于

另请参阅