User Property
.NET Framework Class Library
WebService..::.User Property

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

Namespace:  System.Web.Services
Assembly:  System.Web.Services (in System.Web.Services.dll)
Visual Basic (Declaration)
<BrowsableAttribute(False)> _
Public ReadOnly Property User As IPrincipal
Visual Basic (Usage)
Dim instance As WebService
Dim value As IPrincipal

value = instance.User
C#
[BrowsableAttribute(false)]
public IPrincipal User { get; }
Visual C++
[BrowsableAttribute(false)]
public:
property IPrincipal^ User {
    IPrincipal^ get ();
}
JScript
public function get User () : IPrincipal

Property Value

Type: System.Security.Principal..::.IPrincipal
A IPrincipal representing the ASP.NET server User object.

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.

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
Page view tracker