Learn ASP.NET Web Pages by building a web site from scratch.
Part V: Adding Security.
In this chapter we will:
In the previous chapter we added a registration page and a login page to the web site.
When a membership is registered, the user can login, with his email address and password.
However, user membership and login functions do not automatically restrict (or open) any access to the web site.
Security (access restrictions) has to be added to each of the web pages.
Access restrictions (security) can easily be added to any web page.
Just put the following code inside the page:
The code above executes an if test, asking if the user is logged in. If not, the user is redirected to the login page.
In our example, the page Customers.cshtml, lists customers from the "Northwind" database.
Add the security code at the beginning of the page:
The Customers page above, is a copy of the page from the previous chapter about databases. The security code (added at the beginning) is marked red.
You have added security to your web site, using the WebSecurity object.
For a full reference to the WebSecurity object, please visit our WebSecurity Object Reference.
The perfect solution for professionals who need to balance work, family, and career building.
More than 10 000 certificates already issued!
The HTML Certificate documents your knowledge of HTML.
The HTML5 Certificate documents your knowledge of advanced HTML5.
The CSS Certificate documents your knowledge of advanced CSS.
The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.
The jQuery Certificate documents your knowledge of jQuery.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
Your message has been sent to W3Schools.