Apply Asp.net membership to custom sqlserver

Source: Internet
Author: User

Today, when I used the login control in Asp.net 2005, I used the Asp.net web site management tool. When you are using volume management, security administrators always prompt that the SQL statement cannot be executed. After turning over the SQL statement on the Internet, the system finally solves the problem. The original Article will be posted below.

1. Apply membership in ASP. NET to sqlserver2000/sqlserver2005

By default, membership can be used only when SQL Server Express is installed. However, in many cases, our project already has its own database, which may be in sqlserver2000 or sqlserver2005, how should we use the features provided by membership?

At this time, you need to manually configure membership. Use the aspnet_regsql.exe tool.

First, open the "Visual Studio 2005 command prompt" (you can find the desired tool in Visual Studio toolsin the vs2005 menu and run the aspnet_regsql.exe tool. Then, initialize the database as instructed on the screen.

Open the Asp.net sqlserver Installation Wizard:

For example, configure your database server and database.

OK. Open the database and check the tables required for membership installation, as shown in:

After completing database initialization, You need to configure web. config accordingly.

2. Prepare the Web. config file (Focus)

<Connectionstrings>
<Add name = "constru" connectionstring = "Server =.; database = aspnetdb; uid = sa; Pwd = sa" providername = "system. Data. sqlclient"/>
</Connectionstrings>

<System. Web>
<Membership defaultprovider = "aspnetsqlmp">
<Providers>
<Add name = "aspnetsqlmp"
Type = "system. Web. Security. sqlmembershipprovider, system. Web, version = 2.0.0.0, culture = neutral, publickeytoken = b03f5f7f11d50a3a"
Connectionstringname = "constru"
Enablepasswordretrieval = "false"
Enablepasswordreset = "true"
Requiresquestionandanswer = "true"
Applicationname = "/"
Requiresuniqueemail = "false"
Passwordformat = "hashed"
Maxinvalidpasswordattempts = "5"
Minrequiredpasswordlength = "6"
Minrequirednonalphanumericcharacters = "0"
Passwordattemptwindow = "10"
Passwordstrengthregularexpression = ""/>
</Providers>
</Membership>

<System. Web>

<! --
Connectionstringname: database connection. Set this in Web. config.
Enablepasswordretrieval gets a value indicating whether the current membership provider is configured to allow users to retrieve their passwords.
Enablepasswordreset gets a value indicating whether the current membership provider is configured to allow users to reset their passwords.
Requiresquestionandanswer obtains a value that indicates whether the default membership provider requires the user to answer the password prompt during password reset and retrieval.
Applicationname gets or sets the application name.
Requiresuniqueemail indicates whether a user must provide a unique email address value when creating a user.
Passwordformat indicates the format of the password stored in the membership data storage area. The following is a detailed description.
Maxinvalidpasswordattempts indicates the number of attempts to receive answers to questions that are allowed by users who have been locked for membership.
Minrequiredpasswordlength the minimum length required to obtain the password.
Minrequirednonalphanumericcharacters obtains the minimum number of special characters that a valid Password must contain.
Passwordattemptwindow gets the maximum number of minutes that a question answer attempt is prompted for an invalid or invalid password that is allowed before the user is locked.

A detailed description of passwordformat
Attribute indicates the format of the Stored Password. Passwords can be stored in clear, encrypted, and hashed passwords. Clear passwords are stored in plain text, which improves the performance of storing and retrieving passwords, but are less secure. When the security of data sources is threatened, such passwords are easily read. The encrypted password is encrypted during storage and can be decrypted during password comparison or retrieval. This type of password requires additional processing during storage and retrieval, but it is relatively secure and is not easy to obtain when the security of the data source is threatened. When the hashed password is stored in the database, it uses a one-way hash algorithm and a randomly generated salt value for hash processing. When a password is verified, the password is hash calculated using the salt value in the database for verification. The hash password cannot be retrieved.
-->

 

<Membership>
<Providers>
<Clear/>
<Add name = "aspnetsqlmembershipprovider" type = "system. Web. Security. sqlmembershipprovider" connectionstringname = "conn"
Enablepasswordretrieval = "false" enablepasswordreset = "true" requiresquestionandanswer = "false" requiresuniqueemail = "false"
Maxinvalidpasswordattempts = "5" minrequiredpasswordlength = "6" minrequirednonalphanumericcharacters = "0" passwordattemptwindow = "10"
Applicationname = "/"/>
</Providers>
</Membership>
<Profile>
<Providers>
<Clear/>
<Add name = "aspnetsqlprofileprovider" type = "system. Web. profile. sqlprofileprovider" connectionstringname = "conn" applicationname = "/"/>
</Providers>
</Profile>

<Rolemanager enabled = "true">
<Providers>
<Clear/>
<Add name = "aspnetsqlroleprovider" type = "system. Web. Security. sqlroleprovider" connectionstringname = "conn" applicationname = "/"/>
<Add name = "aspnetwindow#enroleprovider" type = "system. Web. Security. window#enroleprovider" applicationname = "/"/>
</Providers>
</Rolemanager>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.