WebService.User Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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; }
[<System.ComponentModel.Browsable(false)>]
member this.User : System.Security.Principal.IPrincipal
Public ReadOnly Property User As IPrincipal
Property Value
A IPrincipal representing the ASP.NET server User object.
- Attributes
Examples
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
Remarks
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. Authentication in the .NET Framework is configured by placing entries in the web.config file.
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>
For more information on setting up security for an XML Web service see Securing XML Web Services Created Using ASP.NET.
Applies to
See also
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기