Lab 12 – Restrict unauthorised access to...

8
- 1 - Lab 12 – Restrict unauthorised access to webpages 1. Open Visual Studio.NET. From the File menu, click File New Project, from the Visual Studio menu. Under Visual C# -> Web, click on Previous Versions and choose ASP .NET Web Forms Site. Key in name and new solution name as RestrictWebsite and click OK. 2. In the solution explorer, right click on RestrictWebsite and add a new folder named MyiStudio.

Transcript of Lab 12 – Restrict unauthorised access to...

Page 1: Lab 12 – Restrict unauthorised access to webpagesatshare.weebly.com/uploads/1/0/8/9/10891690/lab_12a.pdfASP .NET Web Forms Site. Key in name and new solution name as RestrictWebsite

- 1 -

Lab 12 – Restrict unauthorised access to webpages

1. Open Visual Studio.NET. From the File menu, click File →New → Project, from the Visual Studio

menu. Under Visual C# -> Web, click on Previous Versions and choose ASP .NET Web Forms Site. Keyin name and new solution name as RestrictWebsite and click OK.

2. In the solution explorer, right click on RestrictWebsite and add a new folder named MyiStudio.

Page 2: Lab 12 – Restrict unauthorised access to webpagesatshare.weebly.com/uploads/1/0/8/9/10891690/lab_12a.pdfASP .NET Web Forms Site. Key in name and new solution name as RestrictWebsite

- 2 -

3. Delete About.aspx, Contact.aspx and Default.aspx from the solution explorer

4. Right-click on the MyiStudio folder and add New Item.

5. Select Web Form and check Select master page. Key in Home.aspx as the name and click Add.

6. Select Site.Master and click ok.

7. Repeat step 4 and 6 to create About.aspx, Contact.aspx, and Order.aspx web form.

Page 3: Lab 12 – Restrict unauthorised access to webpagesatshare.weebly.com/uploads/1/0/8/9/10891690/lab_12a.pdfASP .NET Web Forms Site. Key in name and new solution name as RestrictWebsite

- 3 -

8. In the solution explorer, click on Site.Master. Under the source view, look for the following code.

9. Modify the codes as shown below to:i. change application name to MyiStudio and its link to “~/MyiStudio/Home.aspx”.ii. update the links to Home, About and Contact page.iii. add a new list item with name Order and link it to “~/MyiStudio/Order.aspx”.

10. Look for the LogoutPageUrl, and change “~/” to “~/Account/Login” as highlighted in blue below. Once done, save the masterpage.

11. In the solution explorer, open the Account folder and find Login.aspx and expand. Click on Login.aspx.cs.

Page 4: Lab 12 – Restrict unauthorised access to webpagesatshare.weebly.com/uploads/1/0/8/9/10891690/lab_12a.pdfASP .NET Web Forms Site. Key in name and new solution name as RestrictWebsite

- 4 -

12. Find the code as shown below.

13. Modify the code as highlighted below.

14. In the solution explorer, open the Account folder and find Register.aspx and expand. Click on

Register.aspx.cs.

Page 5: Lab 12 – Restrict unauthorised access to webpagesatshare.weebly.com/uploads/1/0/8/9/10891690/lab_12a.pdfASP .NET Web Forms Site. Key in name and new solution name as RestrictWebsite

- 5 -

15. Modify the code as highlighted below.

16. In the solution explorer, click on Home.aspx. Under the design view, type the words as shown below.

17. In the solution explorer, click on About.aspx. Under the design view, type the words as shown below.

18. In the solution explorer, click on Contact.aspx. Under the design view, type the words as shown below.

Page 6: Lab 12 – Restrict unauthorised access to webpagesatshare.weebly.com/uploads/1/0/8/9/10891690/lab_12a.pdfASP .NET Web Forms Site. Key in name and new solution name as RestrictWebsite

- 6 -

19. In the solution explorer, click on Order.aspx. Under the design view, type the words as shown below.

20. Right-Click on Home.aspx and set as start page. Run to test the website. Verify the About and contact webpages

are accessible by clicking on the links.

21. In the solution explorer, click on Web.config. Add in the highlighted codes as shown.

22. Save project. TESTING FOR RESTRICTIONSelect Home.aspx and run the website. Notice that the page cannot be accessed is redirected to the Login page. Click on the About, Contact and Order link to verify that the About, Contact and Order page are also redirected to the Login page.

Page 7: Lab 12 – Restrict unauthorised access to webpagesatshare.weebly.com/uploads/1/0/8/9/10891690/lab_12a.pdfASP .NET Web Forms Site. Key in name and new solution name as RestrictWebsite

- 7 -

23. TESTING FOR WRONG ACCOUNT Key in student as username and password, and click on Log in button. Notice that login is unsuccessful as the account is not valid. Click on the Home, About, Contact and Order link to verify that the Home, About, Contact and Order pages cannot be accessed without a valid login.24. REGISTER AN ACCOUNT Click the [Register] link Register the following account. User name – Student1 Password – Student1

25. After the Register button is pressed, the webpage is redirected to Home page.

25. Click [About] to verify it can be accessed.26. Click [Contact] to verify it can be accessed.27. Click [Order] to verify it can be accessed.

28. Log off.29. Repeat step 4 to 8 to register a new account.User name – Student2Password – Student2*

Page 8: Lab 12 – Restrict unauthorised access to webpagesatshare.weebly.com/uploads/1/0/8/9/10891690/lab_12a.pdfASP .NET Web Forms Site. Key in name and new solution name as RestrictWebsite

- 8 -

30. Login using the Student1 account. Verify that login is successful after the Log in button is pressed. Click on the Home, About, Contact and Order link to verify that the Home, About, Contact and Order pages can be accessed.

31. Log off Student1 account and verify that Student2 account can also be login successfully.

32. Save your project.