- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
Testing for login status in Visual Studio .NET
Testing for login status QR-Code Encoder In .NET Framework Using Barcode printer for ASP.NET Control to generate, create QR-Code image in ASP.NET applications. www.OnBarcode.comBarcode Drawer In VS .NET Using Barcode printer for ASP.NET Control to generate, create Barcode image in ASP.NET applications. www.OnBarcode.comTo see how checking of credentials might be accomplished, open the code-behind page for CreateAccount, CreateAccount.aspx.vb. In the Class Name drop-down at the top left of the editing window, select (Page Events), and in the Method Name drop-down at the top right of the editing window, select the Load event. This will insert an empty code skeleton for the Page_Load event handler. Type the following code inside the Page_Load method: Encoding Linear Barcode In .NET Framework Using Barcode generator for ASP.NET Control to generate, create Linear 1D Barcode image in ASP.NET applications. www.OnBarcode.comUPC - 13 Printer In .NET Framework Using Barcode creation for ASP.NET Control to generate, create EAN 13 image in ASP.NET applications. www.OnBarcode.comIf User.Identity.IsAuthenticated = False Then Response.Redirect("Login.aspx") End If
Create Code-128 In VS .NET Using Barcode creation for ASP.NET Control to generate, create USS Code 128 image in ASP.NET applications. www.OnBarcode.comBarcode Maker In VS .NET Using Barcode creation for ASP.NET Control to generate, create Barcode image in ASP.NET applications. www.OnBarcode.comNow run the application. Before logging in, edit the page address in the browser to go to CreateAccount.aspx. Instead of CreateAccount opening, you will be immediately taken to the login page. 2D Barcode Encoder In VS .NET Using Barcode printer for ASP.NET Control to generate, create Matrix image in ASP.NET applications. www.OnBarcode.comCode 93 Creation In VS .NET Using Barcode creation for ASP.NET Control to generate, create USS Code 93, USS 93 image in ASP.NET applications. www.OnBarcode.comIf you enter a valid username and password at this point, the Login control will try to redirect to Default.aspx, a page that does not exist. Instead, set the DestinationPageUrl property of the Login control to one of the pages in the web site, such as Welcome.aspx. Then on a successful login, the user will be redirected to that page. QR Code JIS X 0510 Maker In Visual Basic .NET Using Barcode generation for .NET framework Control to generate, create Denso QR Bar Code image in .NET framework applications. www.OnBarcode.comQR Code JIS X 0510 Creator In None Using Barcode maker for Word Control to generate, create Quick Response Code image in Word applications. www.OnBarcode.comOn the other hand, if you run the web site and log in, and then edit the browser address to open CreateAccount, you will in fact go to that page. Code128 Reader In Java Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications. www.OnBarcode.comDecoding Barcode In .NET Using Barcode recognizer for .NET Control to read, scan read, scan image in VS .NET applications. www.OnBarcode.comTesting for role-based authentication membership
Creating Barcode In VS .NET Using Barcode generation for Reporting Service Control to generate, create Barcode image in Reporting Service applications. www.OnBarcode.comCode39 Generation In None Using Barcode creator for Excel Control to generate, create Code39 image in Office Excel applications. www.OnBarcode.comYou can also limit access to pages based on the role, or roles, to which the current, logged-in user belongs. Generate Code128 In VB.NET Using Barcode generator for .NET Control to generate, create Code 128B image in .NET applications. www.OnBarcode.comGenerating Data Matrix 2d Barcode In Java Using Barcode printer for Java Control to generate, create DataMatrix image in Java applications. www.OnBarcode.com| Generate Denso QR Bar Code In None Using Barcode creation for Online Control to generate, create QR Code ISO/IEC18004 image in Online applications. www.OnBarcode.comUPC Code Drawer In None Using Barcode creator for Software Control to generate, create UPC-A image in Software applications. www.OnBarcode.com 9: Security and Personalization
QR-Code Creator In Objective-C Using Barcode encoder for iPad Control to generate, create QR Code 2d barcode image in iPad applications. www.OnBarcode.comBarcode Drawer In Objective-C Using Barcode printer for iPad Control to generate, create Barcode image in iPad applications. www.OnBarcode.comAdd another page to the SecurityRoles web site called ManagersPage.aspx. As the name implies, this page will be accessible only to managers. To keep the example simple, for now this page will have only an identifying heading and a button to return to the Welcome page, shown in bold in Example 9-1. You can do this in either Source view or Design view. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="ManagersPage.aspx.vb" Inherits="ManagersPage" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <h1>Manager's Page</h1> <asp:Button ID="btnWelcome" runat="server" Text="Return to Welcome" /> </div> </form> </body> </html> Switch to Design view and double-click the Return to Welcome button to open up an event handler for Click event. Add the following highlighted line of code: Protected Sub btnWelcome_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles btnWelcome.Click Response.Redirect("Welcome.aspx") End Sub While you are at it, add a button to the Welcome page for navigating to the Manager s Page, as shown in Figure 9-23. Set the ID of the button to btnManagersPage, because you will be referring to the button in code elsewhere, and set its Enabled property to False. In a moment, you will add some code to the Page_Load event handler to enable or disable the button depending on the login status. Double-click that button in Design view and add the following highlighted line of code to the Click event handler: Protected Sub Button1_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles btnManagersPage.Click Response.Redirect("ManagersPage.aspx") End Sub Forms-Based Security |
Next, add an event handler for the Page Load event. Then add the following highlighted code to run every time the page loads: Protected Sub Page_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Me.Load If User.Identity.IsAuthenticated = True Then btnManagersPage.Enabled = True Else btnManagersPage.Enabled = False End If End Sub Including both an If and an Else clause ensures that the Enabled state of the button will always be what you want, regardless of the circumstances. Run the app. The Welcome page opens with the Login link and contents of the AnonymousTemplate displayed, and the Manager s Page button is disabled. Log in as a user in the managers role, say dhurwitz, and the button will become enabled. Click that button to move to the Manager s Page; then click the button on that page to return to the Welcome page. There is still a problem with this application, however: If you log in with one of the usernames that are not in the Manager s role, such as tbrady, you still are allowed to go to the Manager s page. Let s fix this. Go to the code-behind for the Manager s page, ManagersPage.aspx.vb. Create an event handler for the Page Load event. Enter the following highlighted code to the event handler: Protected Sub Page_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Me.Load If User.IsInRole("Manager") = False Then Response.Redirect("NoPrivs.aspx") End If End Sub This code will redirect to a page called NoPrivs.aspx if the current user is not a member of the Manager role. So, create that page, making it very similar to ManagersPage.aspx, with only a heading, some text, and a button to redirect back to the Welcome page, as shown in Figure 9-24. Double-click the button to open an event handler for the Click event and enter the following highlighted line of code: Protected Sub btnWelcome_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles btnWelcome.Click Response.Redirect("Welcome.aspx") End Sub Now when you run the app, if you log in with a username that is a member of the Manager role, you can navigate to the Manager s page. Otherwise, you cannot get to the Manager s page; you are directed instead to NoPrivs.
|
|