Export (0) Print
Expand All

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)

'Declaration
Public Shared Sub RequireUser ( _
	userName As String _
)
'Usage
Dim userName As String

WebSecurity.RequireUser(userName)

Parameters

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

ExceptionCondition
InvalidOperationException

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

-or-

The InitializeDatabaseConnection method was not called.

-or-

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.

NoteNote:

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.
Show:
© 2014 Microsoft