visual studio 2005 提供了非常方面的通过 asp.net configuration设置用户以及验证的方式。同时提供了登录控件来操作登录。不过让我难过的是,默认是采用sql express在你的app_data创建一个mdb文件。我现在要使用sql server来存储那么我需要一些配置。
1. 首先到你安装.net frame works框架的目录输入下面命令,安装membership到你的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
..参数-S 表明你是哪个sql server,我目前是本机,所以采用local,其他的自己换名字了。
参数-E 链接SQL 采用windwos的方式,本机不用输入密码呢。
参数-A m 增加membership 的feature
成功完成后,打开你的SQL SERVER 2000你就会看到已经多了一个aspnetdb的数据
2.随后我们在web.config里面添加以下数据库连接,就是链接到刚才新建的数据库
其中呢,Data Source =xxx,表示我的数据源,我采用混合认证方式,User ID=sa Password=Pass,我我自己的用户名密码呢。
<
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.配置站点打开web.config添加以下MebmbershipProvide
其中要注意的就是connectionStringName="aspnetdbConnectionString"这个一定要同你在2步骤中配置的名一样。
我们也可以看到我们添加了一个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,在visual studio 2005 里面工具栏,点击WebSite -ASP.NET Configuration。看到关于web配置页面。
在里面选择Provider ,然后点击其中的“Select a different provider for each feature(advanced)
ok ,已经可以看到在Membership Provide的列表里面看到了MySqlMembershipProvider了,点击Test,成功链接。
5.另外一种也可以的办法如下,修改LocalSqlServer配置。我们可以看到在C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/CONFIG/machine.config里面有这个选项。不过我们不需要修改。只是在我们de webconfig里面重载一个呢。以下是另外一种web.config重点就是connectionstring 里面的东西
<?
xml version="1.0"
?>
<!--
Note: As an alternative to hand editing this file you can use the
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"
/>
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
<
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 by
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.
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
</
system.web
>
</
configuration
>
另外我还看到http://lcx.cnblogs.com/archive/2006/06/29/438836.HTML有个写的不错的web.config可以参考一下是另外一种思路呢
当然还有个更加简单的办法,直接在windows里面运行aspnetsql.exe,参考文档http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx