This documentation is archived and is not being maintained.

WebService.User Property

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

[Visual Basic]
Public ReadOnly Property User As IPrincipal
[C#]
public IPrincipal User {get;}
[C++]
public: __property IPrincipal* get_User();
[JScript]
public function get User() : IPrincipal;

Property Value

A IPrincipal representing the ASP.NET server User object.

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.

Example

[Visual Basic, C#] The example below looks up the authenticated user name and returns that name.

[Visual Basic] 
<%@ 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
    

[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;
      }
 }
    

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

WebService Class | WebService Members | System.Web.Services Namespace | IPrincipal | Securing XML Web Services Created Using ASP.NET

Show: