Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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 void RequireUser(
	String^ 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(array<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(array<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.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.