Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
After creating the user interface that allows the user to login, the next step is to lock down the rest of the website so that when the user tries to navigate to any page of the website they are automatically redirected to the Login page. To see the current behavior, open the file Titles.aspx or any other web page that presents data in the site and run the page in the browser. You should see that the page loads successfully. Close the browser and return to Visual Web Developer and then open the file web.config. This is the XML file in which you configure your website's behavior.
In the file, navigate to the end of the system.web element. If you are using the version that's included with the Exercise Files, you will find that element at the line 83. Notice in the version that's included with the Exercise Files that there is a commented out section. This section isn't in there by default, I placed it in there, so it's not taking any action yet. In order to lock down the entire website, you simply create this authorization element and within the authorization element, you add a deny element with the user's attribute set to a question mark. That means that you are denying access to any anonymous users.
To complete the task of locking down the website then simply remove these comment tokens and then press Ctrl+S to save your changes to the web.config file. Now, go to Titles.aspx again and try running the page in the website. This time you should see that instead of going to the Titles page, you are redirected automatically to the Login page. Take a close look at the URL in the web browser though. Notice that you are redirected to Login.aspx and a return URL attribute is passed in that references the page you try to get to and then log in with the username and password that you have added to the authentication database earlier.
I will login with the user name and the password that I used and then I'll click the Login link and you will see that the page I originally requested, the Title list is successfully loaded. As long as I keep the browser open, I'll be able to navigate around in the website. If I close the web browser and then try to reopen a page of the website, I'll once be redirected back to the Login form. This is because the Login system is using session based cookies; cookies that are only stored in the browser's memory, rather than on disk.
So when you close the browser's windows on the client, that makes it forget the cookies and then the next time, the servers doesn't recognize the user and asks the user to login again. So now, I have created the user interface for logging in and I have also locked down the remainder of the website so only authenticated users can access those pages. The last step is to create a Logout feature, which I'll do in a separate video.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98837 Viewers
61 Video lessons · 86148 Viewers
71 Video lessons · 70000 Viewers
56 Video lessons · 102254 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.