Tutorials References Exercises Sign Up Menu
Create Website Get Certified Pro

WebSecurity - RequireUser()

❮ WebSecurity


The RequireUser() method sets the HTTP status to 401 (Unauthorized) if the specified user is not logged on.

C# and VB Syntax





Parameter Type Description
userID Integer The user ID
userName String The user name

Return Value


Errors and Exceptions

Any access to the WebSecurity object throws an InvalidOperationException if:

  • The InitializeDatabaseConnection() method has not been called
  • SimpleMembership is not initialized (or disabled in the website configuration)


RequireUser() verifies that the current user is the specified user.

To validate that the user is authenticated, use RequireAuthenticatedUser() instead.

To validate that a user is a member of a role (roles), use RequireRoles().

RequireUser() lets only the specified user access the web page. The recommended way to restrict access to a page is to create a role, and use the RequireRoles() method to verify that the user is a member of that role.

❮ WebSecurity