Use Form membership authentication in SQL Server

Source: Internet
Author: User
Tags stack trace connectionstrings

Visual Studio 2005 provides an excellent way to set users and verify users through Asp.net configuration. The logon control is also provided to operate logon. However, what makes me sad is that SQL Express is used by default to create an MDB file in your app_data. I want to use SQL Server for storage now, so I need some configuration.

1. Enter the following command in the directory where you install the. NET Frame Works framework to install membership to your SQL Server.

C:/Documents and Settings/xxpp> C:/Windows/Microsoft. NET/framework/v2.0.50727/Aspnet_regsql.exe-s (local)-e-a m

Start adding the following features:
Membership

... The parameter "-s" indicates which SQL Server you are using. I am using a local computer, so I changed the name of other SQL servers.

The parameter-e link SQL adopts the windwos mode, and the password does not need to be entered on the local machine.

Parameter-a m adds membership feature

After successful completion, open your SQL Server 2000 and you will see an additionalAspnetdb data

2. Then we add the following database connection in Web. config to link to the newly created database.

Here, data source = xxx indicates my data source. I use Hybrid Authentication, user id = sa Password = pass, and my own username and password.

<Connectionstrings>
<Add name = "aspnetdbconnectionstring" connectionstring = "Data Source = xxx; initial catalog = aspnetdb; persist Security info = true; user id = sa; Password = pass"
Providername = "system. Data. sqlclient"/>
</Connectionstrings>

3. Configure the site to open web. config and add the following mebmbershipprovide

Note that connectionstringname = "aspnetdbconnectionstring" must be the same as the name configured in step 2.

We can also see that we have added a mysqlmembershipprovider

<Membership defaultprovider = "mysqlmembershipprovider">
<Providers>
<Clear/>
<Add name = "mysqlmembershipprovider"
Connectionstringname = "aspnetdbconnectionstring"
Applicationname = "myappname"
Type = "system. Web. Security. sqlmembershipprovider,
System. Web, version = 2.0.0.0, culture = neutral,
Publickeytoken = b03f5f7f11d50a3a "/>
</Providers>
</Membership>

 

4. OK. In the toolbar of Visual Studio 2005, click website-ASP. NET configuration. See the web configuration page.

Select the provider, and then click "select a different provider for each feature (advanced)

OK. You can see mysqlmembershipprovider in the membership provide list. Click test.

5. You can also modify the localsqlserver configuration as follows. We can see this option in C:/Windows/Microsoft. NET/framework/v2.0.50727/config/machine. config. But we do not need to modify it. Just reload one in our de webconfig. The following is another kind of Web. config, which focuses on connectionstring.

 

<? XML version = "1.0"?>
<! --
Note: As an alternative to hand editing this file you can use
Web Admin Tool to configure settings for your application. Use
The website-> ASP. NET configuration option in Visual Studio.
A full list of settings and comments can be found in
Machine. config. Comments usually located in
Windowsmicrosoft. netframeworkv2.xconfig
-->
<Configuration xmlns = "http://schemas.microsoft.com/.NetConfiguration/v2.0">
<Appsettings/>
<Connectionstrings>
<Remove name = "localsqlserver"/>
<Add name = "localsqlserver" connectionstring = "Data Source = xpxpcom; initial catalog = aspnetdb; Integrated Security = true"
Providername = "system. Data. sqlclient"/>

<Add name = "aspnetdbconnectionstring" connectionstring = "Data Source = XXXXX; initial catalog = aspnetdb; persist Security info = true; user id = sa; Password = pass"
Providername = "system. Data. sqlclient"/>
</Connectionstrings>
<System. Web>
<! --
Set compilation DEBUG = "true" to insert debugging
Symbols into the compiled page. Because this
Affects performance, set this value to true only
During development.
-->
<Compilation DEBUG = "true"/>
<! --
The <authentication> section enables Configuration
Of the Security Authentication mode used
ASP. NET to identify an incoming user.
-->
<! --
<Authentication mode = "Windows"/>
-->
<Authentication mode = "forms"/>
<! --
The <customerrors> section enables Configuration
Of what to do if/when an unhandled error occurs
During the execution of a request. Specifically,
It enables developers to configure HTML error pages
To be displayed in place of a error stack trace.

<Customerrors mode = "remoteonly" defaultredirect = "genericerrorpage.htm">
<Error statuscode = "403" Redirect = "noaccess.htm"/>
<Error statuscode = "404" Redirect = "filenotfound.htm"/>
</Customerrors>
-->



</System. Web>
</Configuration>

 

 

In addition, I also see

 

Of course, there is a simpler way to run aspnetsql.exe directly in windows, refer to the document http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx

Related Article

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.