How to use C # .NET in ASP.NET to implement a form-based verification translation: MYDOTNET
This article quoted the following names in the Microsoft .Net library: system.data.sqlclient system.web.security ---------------------- ------- Task: Summary: 1. Requirements 2. Create an ASP.NET application 3 with Visual C # .NET. Configure security settings 4 in the web.config file. Create a database table sample to store user information 5. Create a Logon.aspx page 6. Write an event processing code to verify the user identity 7. Create a Default.aspx page 8. Additional Tips Reference Article ------------------------------- Abstract This article demonstrates how to achieve user information through data stock users Form-based verification. (1) The following tools are required to implement 1. Microsoft Visual Studio.net 2. Microsoft Internet Information Services (IIS) Version 5.0 or Update 3. Microsoft SQL Server (2) Create an ASP.NET application 1 with C # .NET 1. Open Visual Studio.net 2. Create a new ASP.NET web application and specify the name and path. (3) Configuring Security Settings in Web.config files This section demonstrates how to configure the ASP.NET application by adding and modifying and nodes to implement form-based authentication. 1. In the Solution window, open the web.config file. 2. Change the Authentication mode to Forms (Note: Default to Windows) 3. Insert the tag and fill in the appropriate properties. (Please link to the MSDN document listed in the article or the QuickStart document to see these properties) First copy the following code, then paste it to section:
authentication> (Note: If you do not specify LoginURL, default is default.aspx) 4. Reject anonymous access by adding the following node: authentication>
(4) Creating a database table sample to store user profile This section demonstrates how to create a sample database to store username, password, and user roles. If you want to implement role-based security, it is necessary to add a field that stores a user role in the database. 1. Open a notepad. 2. Copy the script below to Notepad and save:
IF exists (Select * from sysobjects where id = Object_id (n '[dbo]. [users]') And ObjectProperty (ID, n'susertable ') = 1) DROP TABLE [DBO]. [users] GOCREATE TABLE [DBO] NOT NULL, [PWD] [VARCHAR] (25) NOT NULL, [DBO] Goalter Table [DBO "NOT NULL, [VARCHAR]. ]. [Users] with nocheck address [pk_users] primary key nonclustered ([uname]) on [primary] GO
INSERT INTO USERS VALUES ('user1') Insert INTO Users VALUES ('USER2', 'USER2', 'Admin') Insert Into Users Values ('USER3', 'USER3', 'User " GO 3. Open Microsoft SQL Server, open the Query Analyzer, select the Pubs database in the database list, and then paste the above scripts, run. At this time, create a sample user table that will be used in this sample program in the PUBS database. (5) Creating a Logon.aspx page 1. Create a new web form in the created item, named logon.aspx. 2. Open logon.aspx in the editor to switch to the HTML view. 3. Copy the following code and then "select Paste as an HTML" option in the Edit menu, insert it to the