WebService.User Property

Definition

Gets the ASP.NET server User object. Can be used to authenticate whether a user is authorized to execute the request.

C#
[System.ComponentModel.Browsable(false)]
public System.Security.Principal.IPrincipal User { get; }

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.

ASP.NET (C#)
<%@ 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;
      }
 }

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.

XML
<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

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also