版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、网络编程的技术解析的身份验证有有三种,分别是"Windows | Forms | Passport",其中又以Forms验证用的最多,也最灵活。Forms 验证方式对基于用户的验证授权提供了很好的支持,可以通过一个登录页面验证用户的身份,将此用户的身份发回到客户端的Cookie,之后此用户再访问这个web应用就会连同这个身份Cookie一起发送到效劳端。效劳端上的授权设置就可以根据不同目录对不同用户的访问授权进行控制了。下面大概的看一下Forms的过程。Forms身份验证根本原理:要采用Forms身份验证,先要在应用程序根目录中的中做相应的设置:<authentica
2、tion mode="forms"><forms name=".ASPXAUTH " loginUrl="/login.aspx" timeout="30" path= "/"></forms></authentication>其中<authentication mode= "forms"> 表示本应用程序采用Forms验证方式。1. <forms>标签中的name表示指定要用于身份验证的 Cookie。默认情
3、况下,name 的值是 .ASPXAUTH。采用此种方式验证用户后,以此用户的信息建立一个FormsAuthenticationTicket类型的身份验证票,再加密序列化为一个字符串,最后将这个字符串写到客户端的name指定名字的CookieCookie写到客户端后,此用户再次访问这个web应用时会将连同Cookie一起发送到效劳端,效劳端将会知道此用户是已经验证过的. 再看一下身份验证票都包含哪些信息呢,我们看一下FormsAuthenticationTicket类: CookiePath: 返回发出 Cookie 的路径。注意,窗体的路径设置为 /。由于窗体区分大小写,这是为了防止站点中的
4、 URL 的大小写不一致而采取的一种保护措施。这在刷新 Cookie 时使用Expiration: 获取Cookie 过期的日期/时间。IsPersistent: 如果已发出持久的Cookie,那么返回 true。否那么,身份验证Cookie将限制在浏览器生命周期范围内。IssueDate: 获取最初发出 Cookie 的日期/时间。Name: 获取与身份验证 Cookie 关联的用户名。UserData :获取存储在 Cookie 中的应用程序定义字符串。Version: 返回字节版本号供将来使用。2.<forms>标签中的loginUrl指定如果没有找到任何有效的身份验证Coo
5、kie,为登录将请求重定向到的 URL。默认值为。loginUrl指定的页面就是用来验证用户身份的,一般此页面提供用户输入用户名和密码,用户提交后由程序来根据自己的需要来验证用户的合法性(大多情况是将用户输入信息同数据库中的用户表进行比拟),如果验证用户有效,那么生成同此用户对应的身份验证票,写到客户端的Cookie,最后将浏览器重定向到用户初试请求的页面.一般是用FormsAuthentication.RedirectFromLoginPage 方法来完成生成身份验证票,写回客户端,浏览器重定向等一系列的动作。public static void RedirectFromLoginPage(
6、 string userName, bool createPersistentCookie, string strCookiePath );其中 userName: 就是此用户的标示,用来标志此用户的唯一标示,不一定要映射到用户账户名称. createPersistentCookie: 标示是否发出持久的 Cookie。假设不是持久Cookie,Cookie的有效期Expiration属性有当前时间加上中timeout的时间,每次请求页面时,在验证身份过程中,会判断是否过了有效期的一半,要是的话更新一次cookie的有效期;假设是持久cookie,Expiration属性无意义,这时身份验证票
7、的有效期有cookie的Expires决定,RedirectFromLoginPage方法给Expires属性设定的是50年有效期。strCookiePath: 标示将生成的Cookie的写到客户端的路径,身份验证票中保存这个路径是在刷新身份验证票Cookie时使用这也是生成Cookie的Path,假设没有strCookiePath 参数,那么使用中 path属性的设置。这里可以看到,此方法参数只有三个,而身份验证票的属性有七个,缺乏的四个参数是这么来的:IssueDate: Cookie发出时间由当前时间得出。Expiration:过期时间由当前时间和下面要说的<forms>标签
8、中timeout参数算出。此参数对非持久性cookie有意义。UserData: 这个属性可以用应用程序写入一些用户定义的数据,此方法没有用到这个属性,只是简单的将此属性置为空字符串,请注意此属性,在后面我们将要使用到这个属性。Version: 版本号由系统自动提供.RedirectFromLoginPage方法生成生成身份验证票后,会调用FormsAuthentication.Encrypt 方法,将身份验证票加密为字符串,这个字符串将会是以.ASPXAUTH为名字的一个Cookie的值。这个Cookie的其它属性的生成:Domain,Path属性为确省值,Expires视createPer
9、sistentCookie参数而定,假设是持久cookie,Expires设为50年以后过期;假设是非持久cookie,Expires属性不设置。生成身份验证Cookie后,将此Cookie参加到中,等待发送到客户端。最后RedirectFromLoginPage方法调用方法获取到用户原先请求的页面,重定向到这个页面。3. <forms>标签中的timeout和path,是提供了身份验证票写入到Cookie过期时间和默认路径。以上就是基于Forms身份验证的过程,它完成了对用户身份确实认。下面介绍基于Forms身份验证的访问授权。验证了身份,是要使用这个身份,根据不同的身份我们可以
10、进行不同的操作,处理,最常见的就是对不同的身份进行不同的授权,Forms验证就提供这样的功能。Forms授权是基于目录的,可以针对某个目录来设置访问权限,比方,这些用户可以访问这个目录,那些用户不能访问这个目录。同样,授权设置是在你要控制的那个目录下的文件中来设置: <authorization> <allow users="comma-separated list of users" roles="comma-separat
11、ed list of roles" verbs="comma-separated list of verbs" /> <deny users="comma-separated list of users" roles="comma-separated list of roles"
12、; verbs="comma-separated list of verbs" /></authorization><allow>标签表示允许访问,其中的属性1. users:一个逗号分隔的用户名列表,这些用户名已被授予对资源的访问权限。问号 (?) 允许匿名用户;星号 (*) 允许所有用户。2. roles:一个逗号分隔的角色列表,这些角色已被授予对资源的访问权限。3. verbs:一个逗号分隔的 传输方法列表,这些 传输方法已被授予对资源的访问权限。注册到 ASP.NET 的谓词为
13、 GET、HEAD、POST 和DEBUG。<deny>标签表示不允许访问。其中的属性同上面的。在运行时,授权模块迭代通过 <allow> 和 <deny> 标记,直到它找到适合特定用户的第一个访问规那么。然后,它根据找到的第一项访问规那么是 <allow> 还是 <deny> 规那么来允许或拒绝对 URL 资源的访问。Machine.config 文件中的默认身份验证规那么是 <allow users="*"/>,因此除非另行配置,否那么在默认情况下会允许访问。2.存储过程在使用.NET的过程中,数据
14、库访问是一个很重要的局部,特别是在B/S系统的构建过程中,数据库操作几乎成为了一个必不可少的操作。调用存储过程实现数据库操作使很多程序员使用的方法,而且大多数的程序员都是能使用存储过程就使用存储过程,很少直接使用SQL语句,所以存储过程是很有用而且很重要的。1.存储过程简介简单的说,存储过程是由一些SQL语句和控制语句组成的被封装起来的过程,它驻留在数据库中,可以被客户应用程序调用,也可以从另一个过程或触发器调用。它的参数可以被传递和返回。与应用程序中的函数过程类似,存储过程可以通过名字来调用,而且它们同样有输入参数和输出参数。根据返回值类型的不同,我们可以将存储过程分为三类:返回记录集的存储
15、过程, 返回数值的存储过程也可以称为标量存储过程,以及行为存储过程。顾名思义,返回记录集的存储过程的执行结果是一个记录集,典型的例子是从数据库中检索出符合某一个或几个条件的记录;返回数值的存储过程执行完以后返回一个值,例如在数据库中执行一个有返回值的函数或命令;最后,行为存储过程仅仅是用来实现数据库的某个功能,而没有返回值,例如在数据库中的更新和删除操作。相对于直接使用SQL语句,在应用程序中直接调用存储过程有以下好处:(1)减少网络通信量。调用一个行数不多的存储过程与直接调用SQL语句的网络通信量可能不会有很大的差异,可是如果存储过程包含上百行SQL语句,那么其性能绝比照一条一条的调用SQL
16、语句要高得多。(2)执行速度更快。有两个原因:首先,在存储过程创立的时候,数据库已经对其进行了一次解析和优化。其次,存储过程一旦执行,在内存中就会保存一份这个存储过程,这样下次再执行同样的存储过程时,可以从内存中直接调用。(3)更强的适应性:由于存储过程对数据库的访问是通过存储过程来进行的,因此数据库开发人员可以在不改动存储过程接口的情况下对数据库进行任何改动,而这些改动不会对应用程序造成影响。(4) 布式工作:应用程序和数据库的编码工作可以分别独立进行,而不会相互压制。由以上的分析可以看到,在应用程序中使用存储过程是很有必要的。存储过程的调用方法为了突出新方法的优点,首先介绍一下在.NET中
17、调用存储过程的“官方方法。另外,本文的所有例如程序均工作于SqlServer数据库上,其它情况类似,以后不再一一说明。本文所有例子均采用C#语言。要在应用程序中访问数据库,一般性的步骤是:首先声明一个数据库连接SqlConnection,然后声明一个数据库命令SqlCommand,用来执行SQL语句和存储过程。有了这两个对象后,就可以根据自己的需要采用不同的执行方式到达目的。需要补充的是,不要忘记在页面上添加如下的引用语句: 。就执行存储过程来说,如果执行的是第一类存储过程,那么就要用一个DataAdapter将结果填充到一个DataSet中,然后就可以使用数据网格控件将结果呈现在页面上了;如
18、果执行的是第二和第三种存储过程,那么不需要此过程,只需要根据特定的返回判定操作是否成功完成即可。随着应用程序开发的开展演变,新的应用程序已基于 Web 应用程序模型越来越松散地耦合。如今,越来越多的应用程序使用 XML 来编码要通过网络连接传递的数据。Web 应用程序将 用作在层间进行通信的结构,因此它们必须显式处理请求之间的状态维护。这一新模型大大不同于连接、紧耦合的编程风格,此风格曾是客户端/效劳器时代的标志。在此编程风格中,连接会在程序的整个生存期中保持翻开,而不需要对状态进行特殊处理。在设计符合当今开发人员需要的工具和技术时,Microsoft 认识到需要为数据访问提供全新的编程模型,
19、此模型是基于 .NET Framework 生成的。基于.NET Framework这一点将确保数据访问技术的一致性组件将共享通用的类型系 统、设计模式和命名约定。设计 ADO.NET 的目的是为了满足这一新编程模型的以下要求:具有断开式数据结构;能够与 XML 紧密集成;具有能够组合来自多个、不同数据源的数据的通用数据表示形式;以及具有为与数据库交互而优化的功能,这些要求都是 .NET Framework 固有的内容。在创立 ADO.NET 时,Microsoft 具有以下设计目标。ADO.NET 的设计满足了当今应用程序开发模型的多种要求。同时,该编程模型尽可能地与ADO保持一致,这使当今
20、的ADO开发人员不必从头开始学习全新的数据访问技术。ADO.NET 是 .NET Framework 的固有局部,因此对于 ADO 程序员决不是完全陌生的。与ADO共存。虽然大多数基于.NET 的新应用程序将使用ADO.NET 来编写,但 .NET 程序员仍然可以通过.NET COM 互操作性效劳来使用 ADO。有关 ADO 和 ADO.NET 之间的差异的论述,请参见 上的“ADO.NET for the ADO Programmer。支持N层编程模式为断开式n层编程环境提供了一流的支持,许多新的应用程序都是为该环境编写的。使用断开式数据集这一概念已成为编程模型中的焦点。n 层编程的 解决方
21、案就是DataSet。集成XML支持XML 和数据访问是紧密联系在一起的,即 XML 的全部内容都是有关数据编码的,而数据访问越来越多的内容都与 XML 有关。.NET Framework 不仅支持 Web 标准,它还是完全基于 Web 标准生成的。XML 支持内置在 ADO.NET 中非常根本的级别上。.NET Framework 和ADO.NET 中的 XML 类是同一结构的一局部,它们在许多不同的级别集成。您不必在数据访问效劳集和它们的 XML 相应效劳之间进行选择;它们的设计本来就具有从其中一个跨越到另一个的功能。为什么需要Web Service
22、160; 在通过Internet网购置商品后,你可能对配送方式感到迷惑不解。经常的情况是因配送问题找配送公司而消耗你的大量时间,对于配送公司而言这也不是一项增值效劳。 为了解决这种问题,配送公司需要在不降低平安级别的情况下了解更多的递送信息,然而平安公司设计的平安系统却非常复杂。那么我们能不能只使用80端口web效劳器端口并且只通过web效劳器提供信息呢?所以,我们建立了一个全新的web应用程序以便从核心商业应用程序中获得数据。配送公司将为些东西付money,所有的公司都希望能够将注意力集中在核心商业应用上。 什么是
23、Web Service? Web Service是一种构建应用程序的普通模型,并能在所有支持Internet网通讯的操作系统上实施。Web Service令基于组件的开发和web的结合到达最正确,基于组件的对象模型: Distributed Component Object Model (DCOM), Remote Method Invocation (RMI), 和 Internet Inter-Orb Protocol (IIOP) 都已经发布很长时间了,不幸的是这些模型都依赖于特殊对象模型协议。Web Service利用soap和Xml对这些模型在通讯方面作了进一步的扩展以消除
24、特殊对象模型的障碍。 Web Service主要利用 和soap协议使商业数据在web传输, saop通过 调用商业对象执行远程功能调用,web用户能够使用soap和 通过web调用的方法来调用远程对象。 那么怎样使在位置a的用户明白位置b的Web Service的意思呢?这个问题可以通过和一个一致的共同标准来答复。描述性效劳语言Service Description Language (SDL),soap订约语言SOAP Contract Language (SCL) 和网络访问标准语言Network Accessible Specification Language (
25、NASSL) 都是为这个目的建立的相似语言,然而IBM和微软都同意Web Service Description Language (WSDL)作为Web Service 的标准语言。 Web Service部件的结构由Web Service Description Language.描述,是一份Xml文档,描述了Web Service的属性和接口。新的标准可以在了解到。 最好的学习方法是创立一个Web Service,我们以一个股票报价系统为例,纳斯达克和澳大利亚股票交易系统都是非常有名的例子,他们都提供了一个接口,用于输入公司代码和接受最终成交的股票价格。我们复制一个
26、相同的功能的Web Service。我们的Web Service的输入参数是股票代码,Web Service通过调用中间层商业逻辑函数获得股票价格,商业逻辑函数保持以最小的局部集中在Web Service上。实现这个应用程序的核心部件将是微软 .net framework sdk,我的配置是:操作系统 windows 2000 server,pIII300,300mb内存。创立Web Service的首选集成开发环境(IDE)是,你可以用任何一种文本编辑器轻易创立一个Web Service文件。Technical Analysis of Network Programming1.Identit
27、y Verification of ASP.NETA have verified the identity of three. are "Windows |Forms| Passport." Among them Forms authentication of the largest and most flexible. Forms authentication based on the test will provide a good user support, a page posted by users can verify the identity of users
28、 of this back in his capacity as the Cookie client. Users visit the Web after this application will be sent to the service together with the identity Cookie end. Server can be installed on the authorized list of users under different control of the authority's visit. Then see below about the pro
29、cess. Forms authentication basic tenets : Identity verificationForms authentication using an identification. Applications must be in the root catalog Web.config corresponding set up to do : <authentication mode="forms"> <forms name=".ASPXAUTH " loginUrl="/login.aspx
30、" timeout="30" path= "/"> which <authentication mode= "forms"> said the applications For use Forms authentication. 1. <forms> label said the name designated to be used for identification Cookie. Acquiescence under the name value is. ASPXAUTH. Verific
31、ation users adopt this way, users of this information to establish a similar body FormsAuthenticationTicket Verification of these votes, and then into a string encryption sequence. Finally, the string name of the client wrote the names of designated Cookie. Once the Cookie client wrote, This Web use
32、rs visited this application will be sent to the service together with Cookie end, End users will be aware of this service has been verified before. Identity Verification votes, let's look at what the message contained. We look at FormsAuthenticationTicket categories : CookiePath : return the pat
33、h of Cookie. That the path set up for Windows "/". Because Windows capitalization distinction, which is the URL of the site in order to prevent inconsistencies and capitalization of a protective measure. This in turn use Expiration : Acquiring Cookie Cookie expired Date/Time. IsPersistent
34、: If issued lasting Cookie , return true. Otherwise, the identification Cookie would limit the scope of the life cycle in a browser.IssueDate : The first issue of Cookie Acquisition Date/Time. Name : access to the user name associated with the identification Cookie. UserData : access to applications
35、 stored in the Cookie definition string. Version : byte version return for a future use. 2. If there is no designated loginUrl in the label<forms> to find any effective identification Cookie, will be posted to the URL Redirection request. Default values for default.aspx. LoginUrl esignated pag
36、e is used to verify the identity of users. This page provides general user names and passwords for user input. submitted by the user in accordance with their own procedures need to verify the legitimacy of users (most of the cases is to the user input information with a few According to library user
37、s comparative table), effective verification users, generating the corresponding user identification with this vote, Cookie wrote to the client. Finally maiden request to the user's browser redirection pages.generally used FormsAuthentication.Redirect From Login Page generating capacity to compl
38、ete the certification vote, write any client, browser redirection of a series of moves.Public static void RedirectFormLoginPage(string username, bool createPersistentCookie,string strCookiePath );UserName : the user signs to mark the sole user of this marker, Account name not be mapped to the user.
39、createPersistentCookie : Cookie whether to issue a permanent marker. Cookie is not durable. Cookie valid Expiration attributes which are present time with sed timeout time, each page request, the identity verification process. over half of the period will determine whether, and if so to update a coo
40、kie is valid; If lasting cookie, Expiration attribute senseless. Then the valid votes identification of a cookie Expires, RedirectFromLoginPage method is to set attributes for 50 years Expires valid.StrCookiePath : marker will be generated by the client Cookie Path. Identity Verification votes to pr
41、eserve this path is used in the updated identification votes Cookie(which is also generated Cookie the Path), if not strCookiePath parameters, using the attributes which in web.config of path's Attribute.Here we can see that this method only three parameters, and attributes the identification of
42、 seven votes. so is the shortage of four parameters :IssueDate : Cookie issued drawn from the current time.Expiration : Next time expired by the time and say that the current <forms> label timeout parameters calculated. This persistent cookie parameters on the non-meaningful. UserData :This at
43、tribute can be used a number of applications into the user-defined data. I did not use this method attributes, but simply attribute this home empty string, please take note of this attribute, We will be behind in the use of this attribute. Version : No. version provided by the system automatically.G
44、eneration after generation identification votes RedirectFromLoginPage methods. Call FormsAuthentication.Encrypt will, Encryption will vote for identification string. This will be a string. ASPXAUTH to name a Cookie value. Cookie other attributes of this generation : Domain, the provincial Path To at
45、tribute value Expires As createPersistentCookie parameters, If lasting cookie that expired after 50 years as the Expires; If non-persistent cookie, Expires attribute installed. Generation identification Cookie, Cookie joined this response. Cookies, awaiting sent to clients. Finally RedirectFromLogin
46、Page method invocation FormsAuthentication.Get RedirectUrl way users access to the original request of the page. Redirection of this page. 3. <Forms> labels and the path of the timeout, provide identification to vote is enshrined in the road and acquiescence Cookie time expired. Forms authenti
47、cation is based on the above process, it has completed the confirmation of the identity. Forms are described below based on the identification of the mission.visit authorization Verification of identity is to use this capacity, according to the different operational capacity we can handle. The most
48、common is different for different identities authorized to provide such a certification Forms function. Forms authorization is based on the catalog, catalog can be directed at any authority to set up a visit,for example, These users can access the catalog, users can visit the list of those. Similarl
49、y, the authority is set up in which you want to control the web.config file to set up a catalog : <authorization> <allow users="comma-separated list of users" roles="comma-separated list of roles" verbs="comma-separated list of verbs" /> <deny users="
50、;comma-separated list of users" roles="comma-separated list of roles" verbs="comma-separated list of verbs" /></authorization><Allow> label said that it would allow a visit, which attributes :1.Users : a comma separated list of user names, which users had been
51、 granted the right of access to resources. Question mark(?) Allows anonymous users; An asterisk (*) to allow all users. 2.Roles : the role of a comma separated list of these roles has been given resources to visit the authority.3.Verbs : a comma separated list of transmission method, transmission of
52、 these methods has been awarded the Access to resources. ASP.NET registration to the predicate for GET, HEAD, POST and DEBUG.<Deny> label said not allowed to visit. With the attributes above. In operation, authorized by iterative module <allow> and <deny> markings Until it is the f
53、irst visit to find a suitable user-specific rules. Then, According to find it is the first visit by the rules <allow>or<deny> rules to permit or refuse to URL. resources visit. Machine.config identification documents default rules <allow users="*"/>, unless otherwise allo
54、cation, or acquiescence in the circumstances under which they will allow to visit. 2.The ASP.NET Using Stored ProcedureIn use. NET process, the database is a very important part of especially in the process of building a system / database operated almost become an essential operation. Call stored in
55、 the database used to operate many programmers, Most programmers are able to use stored on the use of stored procedure rarely used in SQL. So memory is very useful and very important process. 1.Introduction of Stored Procedure Simply, storage is control by the process and some SQL language was compo
56、sed of packaging up the process, its presence in the database, client applications can be deployed, can also trigger another process or transfer. Transmission and its parameters can be returned. And the application process function similar names can be stored procedure call, In addition, they have t
57、he same input parameters and output parameters. According to different types of return values, we will be back to record storage process is divided into three categories : the collection storage process. Numerical return to the stored procedure (also called scalar stored), and acts stored. By defini
58、tion, set to return to record the results of the implementation of the storage process is a record set, A typical example is retrieved from the database with the records of one or a few conditions; Numerical implementation of the return process is finished and returned to a storage value For example
59、, in the implementation of a database or function return value of the order; Finally, only acts stored in the database is used to achieve a certain function, and did not return to duty. For example, the database update and delete operations. 2.The benefits of using stored procedure Comparing with th
60、e direct use of SQL and stored in the application process by calling the following benefits :(1) reduce network traffic. Call a stored procedure and the small number of firms directly employ SQL network traffic may not be a great difference. However, if SQL stored procedure contains more than 100 fi
61、rms. One by one, then the performance of the SQL language than the much higher. (2) the speed of implementation. There are two reasons : First, in the process of building the storage time, the database has already conducted an analysis and optimization. Secondly, the storage process, once implemented, will be retained in me
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 班组安全管理八项制度培训课件
- 2025年教育行业数据报告撰写
- 培训课件-上市公司并购的反垄断风险防范
- 财产抵款协议书
- 责任转移协议书
- 货物合同保密协议范本
- 质量纠纷赔偿协议书
- 2025年电工安全操作规程规范培训
- 莱穆瓦耶综合征护理查房
- 骨髓继发恶性肿瘤护理查房
- 2026海南省征信有限公司招聘备考题库(含答案详解)
- 2026重庆市荣昌区人力资源和社会保障局招聘1人笔试备考题库及答案详解
- 2026年城市协管员招聘综合知识(城管知识)题库及答案
- MOOC 隧道工程-中南大学 中国大学慕课答案
- MOOC 创业基础-暨南大学 中国大学慕课答案
- 中考必备1600个词汇核心
- 干货超临界机组给水和汽温控制系统及控制策略详细介绍
- 练字打印用纸,方格纸
- 质量管控手册门窗工程质量控制要点
- GGD安装作业指导书
- geoframe4.5系统培训课件
评论
0/150
提交评论