WebSecurity.GetUserId Method

Returns the ID for a user based on the specified user name.

Namespace:  WebMatrix.WebData
Assembly:  WebMatrix.WebData (in WebMatrix.WebData.dll)

public static function GetUserId(
	userName : String
) : int


Type: System.String
The user name.

Return Value

Type: System.Int32
The user ID.


The SimpleMembershipProvider.Initialize(String, NameValueCollection) method was not called.


The InitializeDatabaseConnection() method was not called.


The SimpleMembershipProvider membership provider is not registered in the configuration of your site. For more information, contact your site's system administrator.

The ID represents the key under which the user profile is stored. The same ID is used to identify a user both in the user profile table and in the membership table.

  • Medium trust for the immediate caller. This member can be used by partially trusted code.