杂记

本文介绍ASP.NET WebForm中父窗体与子窗体间参数传递的方法,包括使用JavaScript进行子窗体关闭及参数回传的技术细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ASP.NET WEB FORM 子父窗体之间参数的传递

两个PAGE的代码如下:
page.aspx(父窗体)
< html >
< body >
< script language = " C# "  runat = " server " >
</ script >
< form id = " Form1 "  method = post runat = " server " >
< asp:TextBox ID = txtName Runat = server ></ asp:TextBox >
< input type = button value = " 弹出子窗口 "  onclick = " Mywin=window.open('subpage.aspx'); " >
</ form >
</ body >
</ html >

subpage.aspx(子窗体)
< html >
< body >
< script language = " JavaScript " >
function  popup()
{
window.opener.document.all[
" txtName " ].value = document.all[ " txtSubName " ].value;
window.close() 
}
</ script >
< script language = " C# "  runat = " server " >
</ script >
< form id = " Form1 "  method = post runat = " server " >
< asp:TextBox ID = txtSubName Runat = server ></ asp:TextBox >
< p >< input type = " button "  value = " 传值并返回父窗口 "  name = " button1 "  onclick = " popup() " ></ p >
</ form >
</ body >
</ html >
几点说明:
1。弹出子窗体,将子窗体的textbox的值传递给父窗体
2。两个button都采用html控件,也可以换成asp.net 的server控件,至于server控件如何调用jscript,这里有个小窍门,button_click事件里执行这样的代码
string  script = " <script language="JavaScript">window.open('subpage.aspx');</script> "
Response.Write(script);

这样就执行了javascript代码

posted @ 2007-04-11 13:16 怎能笑的私藏(藏什么呀?还没有想好,乱堆!) 阅读(6) | 评论 (0)编辑 收藏

Test.asp

<script language="JavaScript">
<!--
function ShowDialog(url, width, height, optValidate) {
 var arr = showModalDialog(url, window, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:no;status:no");
}
//-->
</script>

<form method="post" name="myForm" action="">
<input type="text" name="face" id="face"> <input type="button" value="测  试" onClick="ShowDialog('test.html',450,200)">
</form>


Test.html
<img src="site/bbs/images/userface/Image1.gif" onClick="insertValue('xxxxdddxx')">
<script language="JavaScript">
<!--
function insertValue(strValue)
{
 dialogArguments.document.myForm.face.value = strValue;
}
//-->
</script>

posted @ 2007-04-11 13:14 怎能笑的私藏(藏什么呀?还没有想好,乱堆!) 阅读(16) | 评论 (0)编辑 收藏

2007年4月10日

function log_out()
{
 ht = document.getElementsByTagName("html");
 ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
 if (confirm('你确定要退出?'))
 {
  return true;
 }
 else
 {
  ht[0].style.filter = "";
  return false;
 }
}

posted @ 2007-04-10 16:07 怎能笑的私藏(藏什么呀?还没有想好,乱堆!) 阅读(14) | 评论 (0)编辑 收藏

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css">
<!--
div {
 position:absolute;
 top:50%;
 left:50%;
 margin:-100px 0 0 -100px;
 width:200px;
 height:200px;
 border:1px solid red;
 }

-->
</style>
<div>web标准常见问题大全</div>

posted @ 2007-04-10 16:03 怎能笑的私藏(藏什么呀?还没有想好,乱堆!) 阅读(14) | 评论 (0)编辑 收藏

2006年12月29日

在csdn上很多人都对梅花雨日历所困惑,我刚开始也是没有解决怎么处理的问题,经过不懈努力,终解!
现做了一个例子,供使用者们参考!

/Files/howsmile/Demo.rar

posted @ 2006-12-29 10:28 怎能笑的私藏(藏什么呀?还没有想好,乱堆!) 阅读(136) | 评论 (2)编辑 收藏

2006年9月18日

场景
在本地开发一个asp.net2.0的应用程序时使用了Membership、Roles或Profile特性。你创建了一些新用户,一切都没有问题。

然后把这个程序copy到远程服务器(remote server)上(或者只是移动到你本地服务器上的其他目录)然后运行。由于某种原因,虽然我们能够连接到membership数据库,但是当登陆的时候就会出现错误了,它并不抛出连接错误(connection error),而是提示你像类似的错误:“尝试登陆失败,请重试”(Login attempt unsuccessful, please try again)

原因
这种经常出现的错误的原因是因为membership(或者是roles、profile) provider已经被加入到了程序的web.config里了。但是applicationName属性(attribute)并没有被指定(假设下面的代码的粗体部分布存在地话)

<membership>

            
<providers>

                
<clear/>

                
<add name="AspNetSqlMembershipProvider"

                    type
="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

                    connectionStringName
="LocalSqlServer"

                    enablePasswordRetrieval
="false"

                    enablePasswordReset
="true"

                    requiresQuestionAndAnswer
="true"

  requiresUniqueEmail
="false"

                    passwordFormat
="Hashed"

                    maxInvalidPasswordAttempts
="5"

                    minRequiredPasswordLength
="7"

                    minRequiredNonalphanumericCharacters
="1"

                    passwordAttemptWindow
="10"

                    passwordStrengthRegularExpression
=""  

                    applicationName
="/"  

                


            
</providers>

      
</membership>
/>

 

如果applicationName属性没有被配置的话,当往程序的数据库里添加数据的时候,asp.net会使用程序在web服务器里的虚拟目录路径(vroot Path)自动的计算applicationName的值。我们打开aspnetdb数据库,看aspnet_Applications表,就能了解这一行为:


这个表里为每个applicationName存储了一个具有唯一值(unique)的ApplicationID。因为在我们的程序里注册一个用户的时候并没有指定一个applicationName属性,所以它自动的被设置(计算)为/website8(早期建立项目时的名字)

然后,使用membership API创建的用户会与ApplicationID相关联,这样可以找到applicationName(and in turn the applicationName)。【这样做的目的可以让我们的多个应用程序和站点使用同一个数据库】。打开aspnet_Users表就可以可以看到这些。


如果把这个程序配置成运行在/website8虚拟目录下那么一切都没有问题。但是如果它被copy到其他的地方或服务器上并且更换了虚拟路径(比如说“/app1”或更通常被设置的“/”)后,当Membership APIs被使用时他们就“看”不到数据库里已有的用户了——因为他们将会使用一个不同的applicationName去数据库里寻找用户,相应地过滤application_Users表中的用户。这就是为什么会出现上面错误的原因。

如何解决这个问题
最简单的办法是打开ASPNETDB数据库中的aspnet_Users和aspnet_Application表,去“回想”(figure out,因为那时候我们的虚拟目录叫什么名字我们恐怕已经忘了)创建用户和其他数据的时候的程序名称(去aspnet_Application表中查找)

然后打开你的web.config文件,添加一个applicationName属性到provider声明的地方并且给他赋值,例如,下面的代码我们把它设置为在aspnet_Application表存在的/website8:

< membership >

            
< providers >

                
< clear />

                
< add  name ="AspNetSqlMembershipProvider"

                    type
="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

                    connectionStringName
="LocalSqlServer"

                    enablePasswordRetrieval
="false"

                    enablePasswordReset
="true"

                    requiresQuestionAndAnswer
="true"

  requiresUniqueEmail
="false"

                    passwordFormat
="Hashed"

                    maxInvalidPasswordAttempts
="5"

                    minRequiredPasswordLength
="7"

                    minRequiredNonalphanumericCharacters
="1"

                    passwordAttemptWindow
="10"

                    passwordStrengthRegularExpression
=""  

                    applicationName
="/website8"  

                
/>

            
</ providers >

      
</ membership >

这样程序就能正常的工作,无论我们部署这个程序到那个虚拟目录。

当然,我们还要保证Roles、Profile、WebPartPersonalization或其他的我们配置的providers也要被配置了。

这样我们的程序可以正常工作了。

如果在一开始就避免它:
避免这个问题的最好的办法是始终设置applicationName的值。一个比较好的默认值是使用

posted @ 2006-09-18 18:04 怎能笑的私藏(藏什么呀?还没有想好,乱堆!) 阅读(34) | 评论 (0)编辑 收藏

摘要:

本文介绍了怎么在ASP.NET 2.0中使用Membership新特性,并且介绍了怎么两种不同的Membership的Provider:ActiveDirectoryMembershipProvider和SqlMembershipProvider,前者是基于微软活动目录服务存储用户信息的,或者是基于SQL SERVER存储的。2.0中的这个新机制大大减少了站点用户认证模块的代码量。

目录:

学习目的

使用ActiveDirectoryMembershipProvider

使用SqlMembershipProvider

ActiveDirectoryMembershipProvider的一些设置参数

SqlMembershipProvider的一些设置参数

Membership 的一些API

学习目的:

学会使用Membership进行表单认证

学会设置ActiveDirectoryMembershipProvider

学会使用ActiveDirectoryMembershipProvider建立认证用户

学会设置SqlMembershipProvider

学会建立SQL SERVER Membership数据库

学会使用SqlMembershipProvider建立认证用户

使用ActiveDirectoryMembershipProvider

如果用户信息是存储在活动目录中,而你的内网程序又因为防火墙或者需要适应不同的浏览器等原因不能使用windows集成认证的话,这个时候你可以选择使用ActiveDirectoryMembershipProvider实现表单认证

基本的步骤如下

按照以下步骤来用ActiveDirectoryMembershipProvider实现asp.net程序的用户表单认证

1、配置表单认证

2、配置ActiveDirectoryMembershipProvider

3、建立用户

4、认证用户

1、配置表单认证

要实现表单认证需要设置<authentication>的mode属性为"Forms",然后按照下面的例子配置web.config文件

<authentication mode="Forms">

    <forms loginUrl="Login.aspx"

           protection="All"

           timeout="30"

           name="AppNameCookie"

           path="/FormsAuth"

           requireSSL="false"

           slidingExpiration="true"

           defaultUrl="default.aspx"

           cookieless="UseCookies"

           enableCrossAppRedirects="false"/>

</authentication>

 

·                     loginUrl 指向登录页面,你需要把它放在支持SSL的目录下

·                     Protection 设置成"All"表示为认证凭据同时启用数据来源验证和加密

·                     Timeout 指定了认证的生存时间

·                     name and path are set to unique values for the current application.

·                     requireSSL 设置成"false"表示关闭cookie的SSL加密

·                     slidingExpiration 如果设置成"true"的话,每次访问过期时间将会重置

·                     defaultUrl 就是设置程序的首页

·                     cookieless 设置成"UseCookies"表示使用cookie来传递认证票据

·                     enableCrossAppRedirects 设置成"false"表示程序不接受外部的请求

按照下面的例子为<authentication> 增加<authorization>块,表明只有登录过的用户才能进入程序否则会被转到前面loginUrl设置的页面

<authorization>

   <deny users="?" />

   <allow users="*" />

</authorization>

 

2、配置ActiveDirectoryMembershipProvider

按照下面的例子配置ActiveDirectoryMembershipProvider

<connectionStrings>

  <add name="ADConnectionString"

   connectionString=

    "LDAP://domain.testing.com/CN=Users,DC=domain,DC=testing,DC=com" />

</connectionStrings>

 

<system.web>

 ...

 <membership defaultProvider="MembershipADProvider">

  <providers>

    <add

      name="MembershipADProvider"

      type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web,

            Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

                connectionStringName="ADConnectionString"

                connectionUsername="<domainName>/administrator"

                connectionPassword="password"/>

   </providers>

 </membership>

 ...

</system.web>

 

前面的代码为<providers>添加<add>子节点来为membership指定ActiveDirectoryMembershipProvider,活动目录中存储用户信息的连接字符串如下格式LDAP:// server/userdn

·                     server 是活动目录服务器的IP或者名字

·                     userdn 是活动目录的DN,格式是/CN=Users然后是逗号加上逗号分割开的域名,比如域名是domain.testing.com,连接字符串就是LDAP://domain.testing.com/CN=Users,DC=domain,DC=testing,DC=com

 

注意:确保<membership>的defaultProvider属性设置成了你的ActiveDirectoryMembershipProvider(在这个例子中是MembershipADProvider),如果需要为机器级别改变这个属性,%windir%/Microsoft.NET/Framework/{Version}/Config/machine.config文件中改写原有的AspNetSqlMembershipProvider,AspNetSqlMembershipProvider是使用SQLMembershipProvider在/app_data目录中的SQL Server Express数据库来存放用户信息的机制

3、建立用户

可以使用下面的几种方法新建用户

·                     打开vs.net2005的Website菜单,点击ASP.NET Configuration,然后在安全里面进行设置

·                     建立一个ASP.NET页面,放入一个CreateUserWizard控件,这个控件使用配置过的membership provider来实现建立用户的过程

·                     手动拖放填写用户名和密码的文本框然后使用Membership API的CreateUser方法来实现

 

注意:其实所有这些方法最终还是使用Membership.CreateUser来建立用户

默认配置的ActiveDirectoryMembershipProvider使用UPNs来进行名字印象,如下

attributeMapUsername="userPrincipalName"

因为所有用户名都需要按照下面的格式:

UserName@DomainName

如果手动使用Membership.CreateUser方法来创建用户,这么做

Membership.CreateUser("UserName@DomainName", "P@ssw0rd", "userName@emailAddress");

 

你也能设置config文件来改变映象方式:

attributeMapUsername="sAMAccountName"

如果这样设置的话,用户名就如下格式:

UserName

这样建立用户:

Membership.CreateUser("UserName", "P@ssw0rd", "userName@emailAddress")

注意:你可以设置requiresUniqueEmail为"true"来确保所有用户的mail地址不重复

4、认证用户

要认证用户,你必须要建立一个登录页面,而它也就是唯一不需要验证的页面

可以使用以下方法建立登录页面:

l         用ASP.NET 2.0登录控件,这个控件几乎包含了所有涉及到的操作,它会自动连接配置过的membership provider,不需要写任何代码,登录以后控件可以保存用户信息,比如用加密过的cookie保存。

l         当然你也可以手动来用文本框完成这个过程,可以利用Membership 的ValidateUser来判断登录情况,登录完成后你还需要用FormsAuthentication类来为用户的浏览器写入cookie,下面是例子:

 

if (Membership.ValidateUser(userName.Text, password.Text))

{

  if (Request.QueryString["ReturnUrl"] != null)

  {

    FormsAuthentication.RedirectFromLoginPage(userName.Text, false);

  }

  else

  {

    FormsAuthentication.SetAuthCookie(userName.Text, false);

  }

}

else

{

  Response.Write("Invalid UserID and Password");

}

 

注意:上面两种方式都是使用Membership.CreateUser方法

bool isValidUser = Membership.ValidateUser("UseName@DomainName", "P@ssw0rd");

 

attributeMapUsername="sAMAccountName"

 

bool isValidUser = Membership.ValidateUser("UserName", "P@ssw0rd", "userName@emailAddress")

 

使用SQLMemberShipProvider

当在外网做验证或者内网有没有配置活动目录的时候我们可以使用SQLMembershipProvider来作为验证的数据源,其实默认的设置就是使用SQLMembershipProvider的

基本步骤

按照如下的步骤来为表单验证启用SqlMembershipProvider

1、配置表单认证

2、按照membership数据库

3、建立用户

4、认证用户

1、省略。。。同ActiveDirectoryMembershipProvider

2、按照membership数据库

在使用SqlMembershipProvider以前需要安装一个membership数据库,使用一个SQL SERVER管理员权限登录到服务器,然后在Visual Studio 2005命令行模式下执行下面的语句

 

aspnet_regsql.exe -E -S localhost -A m

看下几个参数:

-E 表明此帐号使用windows集成认证

-S 表明需要安装数据库的服务器名

-A m 表明自动为membership建立相应的表和存储过程

 

注意:Aspnet_regsql 工具同样为其他ASP.NET 2.0特性安装数据库,比如说成员管理,Profile,个性化Web Parts还有Web Events等,当然都会有其他的命令,如果你不使用任何参数的话可以以想到模式运行程序,会允许你在安装的过程中指定数据库服务器和你需要安装的组件

 

3、配置SqlMembershipProvider

Machine.config其实默认就是使用SQL Server Express作为SqlMembershipProvider的,如果你的数据库不是运行在本机的,可以修改下配置

<connectionStrings>

  <add name="MySqlConnection" connectionString="Data Source=MySqlServer;Initial Catalog=aspnetdb;Integrated Security=SSPI;" />

</connectionStrings>

<system.web>

...

  <membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">

    <providers>

      <clear />

      <add

        name="SqlProvider"

        type="System.Web.Security.SqlMembershipProvider"

        connectionStringName="MySqlConnection"

        applicationName="MyApplication"

        enablePasswordRetrieval="false"

        enablePasswordReset="true"

        requiresQuestionAndAnswer="true"

        requiresUniqueEmail="true"

        passwordFormat="Hashed" />

    </providers>

  </membership>

 

更多信息看本文“SqlProviderMembershipProvider属性配置”章节

Step 4. Create Users

4、建立用户:

省略。。。同ActiveDirectoryMembershipProvider

5、认证用户:

省略。。。同ActiveDirectoryMembershipProvider

 

ActiveDirectoryMembershipProvider的属性配置

表1显示了ActiveDirectoryMembershipProvider的属性,默认值和用途

表1: ActiveDirectoryMembershipProvider的属性配置

(这部分不翻译)

 

Attribute

Default Value

Notes

connectionStringName

 

Points to a connection string contained in the connection strings configuration section. This attribute is required because it points to the primary LDAP bind string that is used for create, update, get, and validate operations.

connectionUserName

 

Defines the user name used for authentication purposes when connecting to the directory. If this attribute is specified, the companion connectionPassword attribute must also be specified. This attribute is used to configure a set of credentials that can be used to connect to the directory (instead of using the process account or impersonation credentials that are in effect at the time the provider connects to the directory).

connectionPassword

 

Defines the password used for authentication purposes when connecting to the directory. If this attribute is specified, the companion connectionUserName attribute must also be specified. This attribute is used to configure a set of credentials that can be used to connect to the directory (instead of using the process account or impersonation credentials that are in effect at the time the provider connects to the directory).

connectionProtection

Secure

Defines the transport layer security options that are used when opening connections to the directory. This attribute can have a string value of "Secure" or "None".

If set to "Secure", the provider attempts to select the highest level of connection security available, based on the type of directory that the provider connects to. The protection is determined as follows:
SSL is first attempted because SSL is an option that works with both Active Directory and ADAM (ActiveDirectoryConnection
Protection.Ssl).
If SSL is not available and the provider is connecting to Active Directory or to a domain-joined ADAM instance, encrypt-sign-and-seal is used (ActiveDirectoryConnection
Protection.SignAndSeal).
If neither SSL nor encrypt-sign-seal is available, the provider generates a ProviderException, stating that it could not automatically select a secure connection to the configured directory.

enablePasswordReset

False

Controls whether or not a password can be reset. For security reasons, with the ActiveDirectoryMembershipProvider, this attribute can only be set to true if all of the following have been set:
requiresQuestionAndAnswer is set to true.
passwordQuestion, passwordAnswer, attributeMapFailedPasswordAnswer
Count, attributeMapFailedPassword
AnswerTime, and attributeMapFailed
PasswordAnswerLockoutTime have been mapped to attributes in the directory.
Note: Even if this attribute is set to true, password resets are allowed only if the credentials used to perform the reset have Administrator privileges in Active Directory..

enableSearchMethods

False

Allows an administrator to set whether or not search-oriented methods can be called on the provider instance. Because methods such as Find* and GetAllUsers can be very expensive, the default value for this attribute is false.
The following methods throw a NotSupportedException if they are called when this attribute is set to false:
FindUsersByName
FindUsersByEmail
GetAllUsers

requiresQuestionAnd
Answer

False

Determines whether a password question and answer are required for a password reset.

For security reasons, with ActiveDirectoryMembership
Provider, this attribute can only be set to true if all of the following have been set:
attributeMapPasswordQuestion, attributeMapPasswordAnswer, attributeMapFailedPasswordAnswerCount, attributeMapFailedPasswordAnswerTime, and attributeMapFailedPasswordAnswerLockoutTime

applicationName

/

For this provider, applicationName is included for completeness with other providers. Internally, it does not matter what value is placed here because the application name is not used. The maximum value is 256 characters.

requiresUniqueEmail

False

Specifies whether the e-mail values used in the application must be unique.

maxInvalidPassword
Attempts

5

Indicates the number of failed password attempts or failed password answer attempts allowed before a user's account is locked. When the number of failed attempts equals the value set in this attribute, the user's account is locked out.

For the Active Directory provider, this attribute applies only to managing resets that use a password answer. Active Directory manages bad password attempts internally.

passwordAttempt
Window

10

Indicates the time window, in minutes, during which failed password attempts and failed password answer attempts are tracked.

For the Active Directory provider, this attribute applies only to managing resets that use a password answer. Active Directory manages bad password attempts internally.

passwordAnswer
AttemptLockout
Duration

30

Specifies the duration, in minutes, that a lockout due to a bad password answer is considered still in effect. Because Active Directory uses the concept of timing out bad password lockouts, this attribute is necessary to support a similar concept of timing bad password answer attempts.

minRequiredPassword
Length

7

Specifies the minimum number of characters required in a password. The value can be from 1 to 128.

minRequiredNonAlpha
numericCharacters

1

Specifies the minimum number of non-alphanumeric characters required in a password. This configuration attribute cannot be set to a value greater than the value of the minRequiredPasswordLength. This means the configuration setting must be in the range of
0–minRequiredPasswordLength, inclusive of minRequiredPasswordLength.

passwordStrength
RegularExpression

""

Provides a valid regular expression that the provider will use as part of password strength validation.

attributeMapUsername

userPrincipalName

Defines the mapping from a property on a MembershipUser object to an attribute within the directory.
The only directory attributes for mapping to a username if you are using Active Directory are userPrincipalName or sAMAccountName. The only allowed directory attributes for mapping to username if you are using ADAM is userPrincipalName.

attributeMapEmail

Mail

Defines the mapping from a property on a MembershipUser object to an attribute within the directory.

attributeMapPassword
Question

UNDEFINED

Defines the mapping from a property on a MembershipUser object to an attribute within the directory.

attributeMapPassword
Answer

UNDEFINED

Defines the mapping from a property on a MembershipUser object to an attribute within the directory.

attributeMapFailed
PasswordAnswerCount

UNDEFINED

Defines the mapping from a property on a MembershipUser object to an attribute within the directory.

attributeMapFailed
PasswordAnswerTime

UNDEFINED

Defines the mapping from a property on a MembershipUser object to an attribute within the directory.

attributeMapFailed
PasswordAnswer
LockoutTime

UNDEFINED

Defines the mapping from a property on a MembershipUser object to an attribute within the directory.

如果要启用取回密码你需要在<providers>后增加<add>设置attributeMapPasswordQuestion 和 attributeMapPasswordAnswer 属性来增加ActiveDirectoryMembershipProvider详细见How To: Use Forms Authentication with Active Directory in ASP.NET 2.0.

SqlMembershipProvider Configuration Attributes

SqlMembershipProvider属性配置

表2显示了SqlMembershipProvider的属性,默认值和用途

表 2. SqlMembershipProvider属性配置

 

属性

默认

用途

connectionStringName

 

SQL SERVER的连接字符串

enablePasswordReset

False

密码能否重置
安全原因,只有当
requiresQuestionAndAnswer 设置为 true的时候你才可以设置enablePasswordReset为true

requiresQuestionAnd
Answer

False

是否需要启用取回密码

applicationName

/

设置了它可以让多个应用程序在数据库内有所区分,不需要为每个应用建立一个数据库了

requiresUniqueEmail

False

邮件地址是否需要唯一

maxInvalidPassword
Attempts

5

密码输入错误几次就会锁定用户

passwordAttempt
Window

10

每分钟可以失败的次数

passwordFormat

 

密码方式 Clear, Encrypted, 和Hashed. 第一种是明文存储,效率比较高,但是SQL SERVER中能直接读取密码,不安全. 第二种是不可逆加密,需要一定的加密换算过程,但是比较安全.第三种是可逆加密,密码不能找回

minRequiredPassword
Length

7

指定至少密码需要几位

minRequiredNonAlpha
numericCharacters

1

指定需要是非数字字母作为密码的位数,不能大于minRequiredPassword
Length

passwordStrength
RegularExpression

""

指定强度计算的正则表达式

Membership

表3列出了一些Membership类重要的一些方法参数和用法

表3. Membership 类方法

 

方法名

参数

备注

CreateUser

string username–创建的用户名.
string password–新用户密码
string email–新用户mail地址
string passwordQuestion
string passwordAnswer
bool IsApproved
object providerUserKey

 

DeleteUser

string username–需要删除的用户名
bool removeAllRelatedData

返回true表示删除,false表示没有找到

FindUsersByName

string usernameToMatch
int pageIndex
int pageSize

返回找到的用户的集合,支持通配符 "*", "%" 和 "_".

FindUsersByEmail

string emailToMatch
int pageIndex
int pageSize

 

GeneratePassword

int length
Int numberOfNonAlpha
NumericCharacters

 

GetAllUsers

int pageIndex
int pageSize

返回用户记录集

GetNumberOfUsersOnline

None

返回在线的用户,活动目录不支持

GetUsernameByEmail

string email–需要查找的用户的mail地址

 

UpdateUser

MembershipUser user–需要更新的用户名

 

ValidateUser

string username–需要验证的用户名
string password–需要验证的密码

 

注意  GetAllUsers 方法在 RTM 版本的 .NET Framework 2.0 会取消

 

特别注意

默认情况下表单认证的票据传输是明文的,为了防止票据被盗窃,我们还是建议你为服务器启用SSL。设置requireSSL属性为true来启用SSL,下面的例子显示了怎么启用SSL,还有不管用户使用http还是https形式的url进入网站都能启用,你可以尝试登录到loginUrl指定的页面看看,但是需要保证这个页面是没有任何约束的

<configuration>

  <system.web>

    <authentication mode="Forms">

        <forms loginUrl="https://myserver/mywebapp/secure/Login.aspx"

               protection="All"

               timeout="30"

               name="AppNameCookie"

               path="/FormsAuth"

               requireSSL="true"

               slidingExpiration="true"

               defaultUrl="default.aspx"

               cookieless="UseCookies"

               enableCrossAppRedirects="false"/>

    </authentication>

 

    <!—禁止没有权限的用户 -->

    <authorization>

       <deny users="?" />

       <allow users="*" />

     </authorization>

  </system.web>

</configuration>

 

<!—使得登录页面没有任何限制 -->

<location path="secure">

  <system.web>

    <authorization>

       <allow users="*" />

     </authorization>

  </system.web>

</location>

 

posted @ 2006-09-18 17:59 怎能笑的私藏(藏什么呀?还没有想好,乱堆!) 阅读(72) | 评论 (0)编辑 收藏

select.aspx  
    
  ---------------------------------------------  
    
  <%@ Page Language="C#" %>  
  <%@ import Namespace="System.Data" %>  
  <%@ import Namespace="System.Data.SqlClient" %>  
  <script runat="server">  
    
   protected void Page_Load(Object sender, EventArgs e)  
   {  
   int intPageNo,intPageSize,intPageCount;  
   intPageSize = 25;  
   if (Request["CurrentPage"]==null)  
   {  
   intPageNo = 1;  
   }  
   else  
   {  
   intPageNo = Int32.Parse(Request["CurrentPage"]);  
   }  
    
    
   SqlConnection mySqlConnection = new SqlConnection("server=(local);Database=test;user id=sa;password=");  
   SqlCommand mySqlCommand = new SqlCommand("up_GetTopicList", mySqlConnection);  
   mySqlCommand.CommandType = CommandType.StoredProcedure;  
    
   SqlParameter workParm;  
    
   //搜索表字段,以","号分隔  
   workParm = mySqlCommand.Parameters.Add("@a_TableList", SqlDbType.VarChar, 200);  
   mySqlCommand.Parameters["@a_TableList"].Value = "OFFERID,type,offertime";  
    
   //搜索表名  
   workParm = mySqlCommand.Parameters.Add("@a_TableName", SqlDbType.VarChar, 30);  
   mySqlCommand.Parameters["@a_TableName"].Value = "offer";  
    
   //搜索条件,如"select * from aa where a=1 and b=2 and c=3"则条件为"where a=1 and b=2 and c=3"  
   workParm = mySqlCommand.Parameters.Add("@a_SelectWhere", SqlDbType.VarChar, 500);  
   mySqlCommand.Parameters["@a_SelectWhere"].Value = "where type=’idl’";  
    
   //表主键字段名,必须为INT 型  
   workParm = mySqlCommand.Parameters.Add("@a_SelectOrderId", SqlDbType.VarChar, 50);  
   mySqlCommand.Parameters["@a_SelectOrderId"].Value = "offerid";  
    
   //排序,可以使用多字段排序但主键字段必需在最前面  
   workParm = mySqlCommand.Parameters.Add("@a_SelectOrder", SqlDbType.VarChar, 50);  
   mySqlCommand.Parameters["@a_SelectOrder"].Value = "order by offerid desc";  
    
   //页号  
   workParm = mySqlCommand.Parameters.Add("@a_intPageNo", SqlDbType.Int);  
   mySqlCommand.Parameters["@a_intPageNo"].Value = intPageNo;  
    
   //每页显示数  
   workParm = mySqlCommand.Parameters.Add("@a_intPageSize", SqlDbType.Int);  
   mySqlCommand.Parameters["@a_intPageSize"].Value = intPageSize;  
    
   //总记录数(存储过程输出参数)  
   workParm = mySqlCommand.Parameters.Add("@RecordCount", SqlDbType.Int);  
   workParm.Direction = ParameterDirection.Output;  
    
   //当前页记录数(存储过程返回值)  
   workParm = mySqlCommand.Parameters.Add("RowCount", SqlDbType.Int);  
   workParm.Direction = ParameterDirection.ReturnValue;  
    
   mySqlConnection.Open();  
   Repeater.DataSource = mySqlCommand.ExecuteReader();  
    
   Repeater.DataBind();  
    
   mySqlConnection.Close();  
    
   Int32 RecordCount = (Int32)mySqlCommand.Parameters["@RecordCount"].Value;  
   Int32 RowCount = (Int32)mySqlCommand.Parameters["RowCount"].Value;  
    
   LabelRecord.Text = RecordCount.ToString();  
   LabelRow.Text = intPageNo.ToString();  
   intPageCount = RecordCount/intPageSize;  
   if ((RecordCount%intPageSize)>0)  
   intPageCount += 1;  
   LabelPage.Text = intPageCount.ToString();  
    
   if (intPageNo>1)  
   {  
   HLFistPage.NavigateUrl = "select.aspx?CurrentPage=1";  
   HLPrevPage.NavigateUrl = String.Concat("select.aspx?CurrentPage=","",intPageNo-1);  
   }  
   else  
   {  
   HLFistPage.NavigateUrl = "";  
   HLPrevPage.NavigateUrl = "";  
   //HLFistPage.Enabled = false;  
   //HLPrevPage.Enabled = false;  
   }  
    
   if (intPageNo<intPageCount)  
   {  
   HLNextPage.NavigateUrl = String.Concat("select.aspx?CurrentPage=","",intPageNo+1);  
   HLEndPage.NavigateUrl = String.Concat("select.aspx?CurrentPage=","",intPageCount);  
   }  
   else  
   {  
   HLNextPage.NavigateUrl = "";  
   HLEndPage.NavigateUrl = "";  
   //HLNextPage.Enabled=false;  
   //HLEndPage.Enabled=false;  
   }  
    
   }  
    
  </script>  
  <html>  
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">  
  <head>  
   <link href="/style.css" rel="stylesheet" />  
  <style type="text/css">  
  .high { font-family: "宋体"; font-size: 9pt; line-height: 140%}  
  .mid { font-size: 9pt; line-height: 12pt}  
  .small { font-size: 9pt; line-height: normal}  
  .TP10_5 {  
   font-size: 14px;  
   line-height: 140%;  
  }  
  </style>  
   <style type="text/css">A:link {  
   COLOR: #cc6666  
  }  
  </style>  
  </head>  
  <body>  
   <form runat="server">  
  <span class="high"> 第<font color="#CC0000"><asp:Label id="LabelRow" runat="server"/></font>页 | 共有<asp:Label id="LabelPage" runat="server"/>页  
   | <asp:Label id="LabelRecord" runat="server"/>条信息 |  
   <asp:HyperLink id="HLFistPage" Text="首页" runat="server"/>  
   | <asp:HyperLink id="HLPrevPage" Text="上一页" runat="server"/>  
   | <asp:HyperLink id="HLNextPage" Text="下一页" runat="server"/>  
   | <asp:HyperLink id="HLEndPage" Text="尾页" runat="server"/></span><br>  
    
   <asp:Repeater id=Repeater runat="server">  
    
   <HeaderTemplate>  
    
   <table width="583" border="0" cellspacing="0" cellpadding="0">  
   <tr>  
   <td bgcolor="#000000"><table width="100%" border="0" cellpadding="4" cellspacing="1" class="TP10_5">  
   <tr bgcolor="#999999">  
   <td align="center"> <strong><font color="#FFFFFF">订单号</font></strong></td>  
   <td align="center"> <strong><font color="#FFFFFF">服务项目</font></strong></td>  
   <td align="center"> <strong><font color="#FFFFFF">预订日期</font></strong></td>  
   <td align="center"> <strong><font color="#FFFFFF">操作人员</font></strong></td>  
   <td align="center"> <strong><font color="#FFFFFF">分配状态</font></strong></td>  
   <td> <div align="center"></div></td>  
   </tr>  
   </HeaderTemplate>  
    
   <ItemTemplate>  
    
   <tr align="center" bgcolor="#FFFFFF" class="small" onMouseOver=’this.style.background="#CCCCCC"’ onMouseOut=’this.style.background="#FFFFFF"’>  
   <td><%# DataBinder.Eval(Container.DataItem, "offerid") %></td>  
   <td><%# DataBinder.Eval(Container.DataItem, "type") %></td>  
   <td><%# DataBinder.Eval(Container.DataItem, "offertime") %></td>  
   <td> </td>  
   <td> </td>  
   <td><a href=" javascript:void(window.open(’info.asp?id=<%# DataBinder.Eval(Container.DataItem, "offerid") %>’,’订单分配’,’height=600,width=1000’))">订单详情</a></td>  
   </tr>  
    
   </ItemTemplate>  
    
   <FooterTemplate>  
    
   </table></td>  
   </tr>  
   </table>  
    
   </FooterTemplate>  
    
   </asp:Repeater>  
    
   </form>  
  </body>  
  </html>  
    
  ------------------------------------------------  
    
    
  up_GetTopicList.sql  
    
  ------------------------------------------------  
    
  CREATE proc up_GetTopicList  
   @a_TableList Varchar(200),  
   @a_TableName Varchar(30),  
   @a_SelectWhere Varchar(500),  
   @a_SelectOrderId Varchar(20),  
   @a_SelectOrder Varchar(50),  
   @a_intPageNo int,  
   @a_intPageSize int,  
   @RecordCount int OUTPUT  
  as  
   /*定义局部变量*/  
   declare @intBeginID int  
   declare @intEndID int  
   declare @intRootRecordCount int  
   declare @intRowCount int  
   declare @TmpSelect NVarchar(600)  
   /*关闭计数*/  
   set nocount on  
    
   /*求总共根贴数*/  
    
   select @TmpSelect = ’set nocount on;select @SPintRootRecordCount = count(*) from ’+@a_TableName+’ ’+@a_SelectWhere  
   execute sp_executesql  
   @TmpSelect,  
   N’@SPintRootRecordCount int OUTPUT’,  
   @SPintRootRecordCount=@intRootRecordCount OUTPUT  
    
  select @RecordCount = @intRootRecordCount  
    
   if (@intRootRecordCount = 0) --如果没有贴子,则返回零  
   return 0  
    
   /*判断页数是否正确*/  
   if (@a_intPageNo - 1) * @a_intPageSize > @intRootRecordCount  
   return (-1)  
    
   /*求开始rootID*/  
   set @intRowCount = (@a_intPageNo - 1) * @a_intPageSize + 1  
   /*限制条数*/  
    
   select @TmpSelect = ’set nocount on;set rowcount @SPintRowCount;select @SPintBeginID = ’+@a_SelectOrderId+’ from ’+@a_TableName+’ ’+@a_SelectWhere+’ ’+@a_SelectOrder  
   execute sp_executesql  
   @TmpSelect,  
   N’@SPintRowCount int,@SPintBeginID int OUTPUT’,  
   @SPintRowCount=@intRowCount,@SPintBeginID=@intBeginID OUTPUT  
    
    
   /*结束rootID*/  
   set @intRowCount = @a_intPageNo * @a_intPageSize  
   /*限制条数*/  
    
   select @TmpSelect = ’set nocount on;set rowcount @SPintRowCount;select @SPintEndID = ’+@a_SelectOrderId+’ from ’+@a_TableName+’ ’+@a_SelectWhere+’ ’+@a_SelectOrder  
   execute sp_executesql  
   @TmpSelect,  
   N’@SPintRowCount int,@SPintEndID int OUTPUT’,  
   @SPintRowCount=@intRowCount,@SPintEndID=@intEndID OUTPUT  
    
    
  if @a_SelectWhere=’’ or @a_SelectWhere IS NULL  
   select @TmpSelect = ’set nocount off;set rowcount 0;select ’+@a_TableList+’ from ’+@a_TableName+’ where ’+@a_SelectOrderId+’ between ’  
  else  
   select @TmpSelect = ’set nocount off;set rowcount 0;select ’+@a_TableList+’ from ’+@a_TableName+’ ’+@a_SelectWhere+’ and ’+@a_SelectOrderId+’ between ’  
    
  if @intEndID > @intBeginID  
   select @TmpSelect = @TmpSelect+’@SPintBeginID and @SPintEndID’+’ ’+@a_SelectOrder  
  else  
   select @TmpSelect = @TmpSelect+’@SPintEndID and @SPintBeginID’+’ ’+@a_SelectOrder  
    
   execute sp_executesql  
   @TmpSelect,  
   N’@SPintEndID int,@SPintBeginID int’,  
   @SPintEndID=@intEndID,@SPintBeginID=@intBeginID  
    
   return(@@rowcount)  
   --select @@rowcount  
  GO

posted @ 2006-09-18 16:04 怎能笑的私藏(藏什么呀?还没有想好,乱堆!) 阅读(38) | 评论 (0)编辑 收藏

     摘要: 1.建立用户控件Pager.ascx 1.1 html <script language="javascript">        function callButtonEvent()    {      ...   阅读全文

posted @ 2006-09-18 16:00 怎能笑的私藏(藏什么呀?还没有想好,乱堆!) 阅读(66) | 评论 (0)编辑 收藏

刚开始打开PetShop项目的时候,我们未免会被如此多的项目吓一跳,不过只要用心的去分析,看懂它并不是非常难的事。

首先我们来看一下WEB项目,因为我们做WEB应用程序首先想到的就是看看页面是怎么实现的,然后一路追溯下去,直到看明白程序是如何把数据显示到页面和如何处理页面的数据的。

比如说首页吧,Default.aspx,我们看到首页很简单,大多数是静态的,只显示了一个Categories菜单,下面是对应的HTML代码

<PetShopControl:NavigationControl ID="Categories" runat="server"></PetShopControl:NavigationControl>

而这些PetShopControl,NavigationControl标签是什么呢,我们可以在页面HTML代码的上方看到一行

<%@ Register Src="Controls/NavigationControl.ascx" TagName="NavigationControl" TagPrefix="PetShopControl" %>

指令,通过这行指令我们可以看到Categories菜单是通过NavigationControl.ascx用户控件实现的

那好,我们现在就来打开 NavigationControl.ascx ,NavigationControl.ascx 里面有一个Repeater控件,然后我们来看看NavigationControl.ascx的后台代码NavigationControl.ascx.cs

页面初绐化Page_Load调用两个函数GetControlStyle();BindCategories();

其中GetControlStyle()是为了实现菜单在首页和其它页面显示不同的风格,BindCategories()方法就是绑定数据了。

BindCategories() {

Category category = new Category();

repCategories.DataSource = category.GetCategories();

repCategories.DataBind();

}

在BindCategories()方法中有个类Category,Category是在BLL项目中实现的,我们可以单击右键点转到定义快速的找到它,category.GetCategories()方法我们也可以快速的找到它的定义

表现层到这就转到业务层了,现在我们来看看业务层如何实现Category类,业务层的GetCategories()方法实现如下

public IList<CategoryInfo> GetCategories() {

return dal.GetCategories();

}

而变量 dal 在类中有定义

private static readonly ICategory dal = PetShop.DALFactory.DataAccess.CreateCategory();

然后我们再看到PetShop.DALFactory.DataAccess.CreateCategory()

在DataAccess类的CreateCategory()方法中我们所看到的并没有具体的数据操作,取而代之的是

string className = path + ".Category";

return (PetShop.IDAL.ICategory)Assembly.Load(path).CreateInstance(className);

我们可以看到 path 的定义

private static readonly string path = ConfigurationManager.AppSettings["WebDAL"];

path是WEB.config中定义的WebDAL节点值,我们来看看Web.config中的WebDAL值,如果装的是SQL数据库的话应该是 “PetShop.SQLServerDAL”

原来语句“Assembly.Load(path).CreateInstance(className)”就是通过Web.config配置来实例化PetShop.SQLServerDAL集合中的Category类,然后我们才在PetShop.SQLServerDAL.Category看到方法GetCategories()的具体实现

但是何必运用如此烦杂的步骤来实现对数据的操作呢,细想一下,不同的用户有不同的数据库,例如我们可以使用SQL SERVER,也可以使用Oracle数据库,为了轻松的实现对不同数据库的访问而不修改业务层,降低各层之间的偶合,所以PetShop运用了设计模式中的抽象工厂模式Factory,而为什么表现层和业务层之间不需要这样做,因为业务层的业务规则一般都是固定的,所以没必要写几个业务层,如果应用程序中的业务层是时常变动的,或开发的是通用的WEB应用程序,针对不同的企业有不同的业务层,而表现层却一样,也可以运用抽象工厂模式。

PetShop的整体架构就是这样子了,可以说这是经典的三层架构啦!!

由于整体已经有22个项目,所以,对于初学者一看就晕了,所以,我做了分解,可以大体上分几块去理解。

序号

项目名称

描述

1

WEB

表示层

2

Model

业务实体

3

BLL

业务逻辑层

4

DALFactory

数据层的抽象工厂

5

IDAL

数据访问层接口定义

6

SQLServerDAL

SQLServer数据访问层

7

OracleDAL

Oracle数据访问层

8

DBUtility

数据库访问组件基础类

9

CacheDependencyFactory

缓存依赖类的工厂类

10

ICacheDependency

缓存依赖类接口

11

TableCacheDependency

缓存依赖实现类

12

IBLLStrategy

同步/异步处理策略接口(实现在bll根据配置反射选择)

13

MessagingFactory

异时处理消息队列的抽象工厂

14

IMessaging

异时处理消息队列接口定义

15

MSMQMessaging

异时处理消息队列的实现

16

Profile

Profile的数据访问层

17

ProfileDALFactory

ProfileDAL的工厂类(反射创建ProfileDAL)

18

IProfileDAL

Profile的数据访问层接口定义

19

OracleProfileDAL

Oracle的Profile Providers

做用户状态管理

20

SQLProfileDAL

SQL Server 的Profile Providers

做用户状态管理

21

Membership

Membership认证和授权管理

22

OrderProcessor

后台处理进程,处理订单队列


 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值