1. 在sql server中的设置

  运行aspnet_regsql.exe,一般来说它位于:C:\WINDOWS \Microsoft.NET\Framework\v2.0.50727

   例如:aspnet_regsql.exe -S [服务器] -U [用户名] -P [用户密码]-A all -d [数据库名称]

    此方法使用后会在指定数据库生成几个表,还存储过程也视图,如下:

  


2.配置web.config

 membership既然是用于成员资格管理,当然要求登录验证身份,所以首先加上一个forms验证。

 

<authentication mode="Forms">
<forms loginUrl="login.aspx" name=".aspxlogin"/>
</authentication>

 

 


同样在system.web节点下添加membership节点。

<connectionStrings>
<add name="SqlServices" connectionString="Data Source=MySqlServer;Integrated Security=SSPI;Initial Catalog=aspnetdb;" />
</connectionStrings>
<system.web>
<membership defaultProvider="SqlServices" userIsOnlineTimeWindow="15" hashAlgorithmType="">
<!--defaultProvider :提供程序的名称。默认为 AspNetSqlMembershipProvider。如果你有多个Provider的话,指定一个默认值是明智的做法-->
<!--userIsOnlineTimeWindow :指定用户在最近一次活动的日期/时间戳之后被视为联机的分钟数。-->
<!--hashAlgorithmType :用于哈希密码的算法的标识符,或为空以使用默认哈希算法。-->
<providers>
<clear/>
<add
connectionStringName="SqlServices"
enablePasswordRetrieval
="false"
enablePasswordReset
="true"
requiresQuestionAndAnswer
="true"
applicationName
="/"
requiresUniqueEmail
="false"
passwordFormat
="Hashed"
maxInvalidPasswordAttempts
="5"
minRequiredPasswordLength
="7"
minRequiredNonalphanumericCharacters
="1"
passwordAttemptWindow
="10"
passwordStrengthRegularExpression
=""
name
="AspNetSqlMembershipProvider"
type
="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<!--connectionStringName :membership数据库的连接名称。-->
<!--enablePasswordRetrieval :指示当前成员资格提供程序是否配置为允许用户检索其密码。-->
<!--enablePasswordReset :指示当前成员资格提供程序是否配置为允许用户重置其密码。-->
<!--requiresQuestionAndAnswer :指示默认成员资格提供程序是否要求用户在进行密码重置和检索时回答密码提示问题。-->
<!--applicationName :应用程序的名称。-->
<!--requiresUniqueEmail :指示成员资格提供程序是否配置为要求每个用户名具有唯一的电子邮件地址。-->
<!--passwordFormat :指示在成员资格数据存储区中存储密码的格式。值可选Clear、Encrypted 和 Hashed。Clear 密码以明文形式存储,这可以提高存储和检索密码的性能,但安全性较差,当数据源安全性受到威胁时此类密码很容易被读取。Encrypted 密码在存储时进行了加密,可以在比较或检索密码时进行解密。此类密码在存储和检索时需要进行额外的处理,但比较安全,在数据源的安全性受到威胁时不容易被获取。Hashed 密码在存储到数据库时使用单向哈希算法和随机生成的 salt 值进行哈希处理。在验证某一密码时,将用数据库中的 salt 值对该密码进行哈希计算以进行验证。无法检索哈希密码。-->
<!--maxInvalidPasswordAttempts :锁定成员资格用户前允许的无效密码或无效密码提示问题答案尝试次数。-->
<!--minRequiredPasswordLength :密码所要求的最小长度。-->
<!--minRequiredNonalphanumericCharacters :有效密码中必须包含的最少特殊字符数。-->
<!--passwordAttemptWindow :在锁定成员资格用户之前允许的最大无效密码或无效密码提示问题答案尝试次数的分钟数。这是为了 防止不明来源反复尝试来猜测成员资格用户的密码或密码提示问题答案的额外措施。-->
<!--passwordStrengthRegularExpression :计算密码的正则表达式。-->
</providers>
</membership>

</system.web>

 


 

为membership配置web.config后,再配置其角色管理roleManager,也是在system.web下。

 

<roleManager defaultProvider="SqlProvider"
enabled
="true"
cacheRolesInCookie
="true"
cookieName
=".ASPROLES"
cookieTimeout
="30"
cookiePath
="/"
cookieRequireSSL
="false"
cookieSlidingExpiration
="true"
cookieProtection
="All" >
<providers>
<add
name="SqlProvider"
type
="System.Web.Security.SqlRoleProvider"
connectionStringName
="SqlServices"
applicationName
="SampleApplication" />
</providers>
</roleManager>

 


 

3.使用Membership类(主要:此类都属于静态类)



4.使用Role类



posted on 2011-01-20 18:28  blog 明天  阅读(366)  评论(0编辑  收藏  举报