在SQL Sever中使用form membership认证

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"   />

    
< 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.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        
-->
  


  
</ 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值