WebSecurity.RequireUser Method (String)

If the current user does not match the specified user name, sets the HTTP status to 401 (Unauthorized).

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

public static function RequireUser(
	userName : String


Type: System.String
The name of the user to compare.


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.

This method verifies that the current user is the specified user. If the current user is not the specified user, the HTTP status is set to 401 (Unauthorized).

To validate that the user is authenticated, use the RequireAuthenticatedUser() method. To validate that a user is a member of a role or set of roles, use the RequireRoles(String[]) method.


This method will let only the specified user access the web page. The recommended way to restrict access to a web page is to create a role, and then use the RequireRoles(String[]) method to verify that the current user is a member of that role.

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