ASP论文外文翻译从底层了解ASP.NET的结构.doc

上传人:文库蛋蛋多 文档编号:2384341 上传时间:2023-02-17 格式:DOC 页数:13 大小:74.50KB
返回 下载 相关 举报
ASP论文外文翻译从底层了解ASP.NET的结构.doc_第1页
第1页 / 共13页
ASP论文外文翻译从底层了解ASP.NET的结构.doc_第2页
第2页 / 共13页
ASP论文外文翻译从底层了解ASP.NET的结构.doc_第3页
第3页 / 共13页
ASP论文外文翻译从底层了解ASP.NET的结构.doc_第4页
第4页 / 共13页
ASP论文外文翻译从底层了解ASP.NET的结构.doc_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《ASP论文外文翻译从底层了解ASP.NET的结构.doc》由会员分享,可在线阅读,更多相关《ASP论文外文翻译从底层了解ASP.NET的结构.doc(13页珍藏版)》请在三一办公上搜索。

1、原文1A low-level Look at the ASP.NET ArchitectureAbstractASP.NET is a powerful platform for building Web applications that provides a tremendous amount of flexibility and power for building just about any kind of Web application. Most people are familiar only with the high level frameworks like WebFor

2、ms and WebServices which sit at the very top level of the ASP.NET hierarchy. In this article Ill describe the lower level aspects of ASP.NET and explain how requests move from Web Server to the ASP.NET runtime and then through the ASP.NET Http Pipeline to process requests. What is ASP.NETLets start

3、with a simple definition: What is ASP.NET? I like to define ASP.NET as follows:ASP.NET is a sophisticated engine using Managed Code for front to back processing of Web Requests.Its much more than just WebForms and Web ServicesASP.NET is a request processing engine. It takes an incoming request and p

4、asses it through its internal pipeline to an end point where you as a developer can attach code to process that request. This engine is actually completely separated from HTTP or the Web Server. In fact, the HTTP Runtime is a component that you can host in your own applications outside of IIS or any

5、 server side application altogether. The runtime provides a complex yet very elegant mechanism for routing requests through this pipeline. There are a number of interrelated objects, most of which are extensible either via subclassing or through event interfaces at almost every level of the process,

6、 so the framework is highly extensible. Through this mechanism its possible to hook into very low level interfaces such as the caching, authentication and authorization. You can even filter content by pre or post processing requests or simply route incoming requests that match a specific signature d

7、irectly to your code or another URL. There are a lot of different ways to accomplish the same thing, but all of the approaches are straightforward to implement, yet provide flexibility in finding the best match for performance and ease of development.The entire ASP.NET engine was completely built in

8、 managed code and all of the extensibility functionality is provided via managed code extensions. This is a testament to the power of the .NET framework in its ability to build sophisticated and very performance oriented architectures. Above all though, the most impressive part of ASP.NET is the tho

9、ughtful design that makes the architecture easy to work with, yet provides hooks into just about any part of the request processing.With ASP.NET you can perform tasks that previously were the domain of ISAPI extensions and filters on IIS with some limitations, but its a lot closer than say ASP was.

10、ISAPI is a low level Win32 style API that had a very meager interface and was very difficult to work for sophisticated applications. Since ISAPI is very low level it also is very fast, but fairly unmanageable for application level development. So, ISAPI has been mainly relegated for some time to pro

11、viding bridge interfaces to other application or platforms. But ISAPI isnt dead by any means. In fact, ASP.NET on Microsoft platforms interfaces with IIS through an ISAPI extension that hosts .NET and through it the ASP.NET runtime. ISAPI provides the core interface from the Web Server and ASP.NET u

12、ses the unmanaged ISAPI code to retrieve input and send output back to the client. The content that ISAPI provides is available via common objects like HttpRequest and HttpResponse that expose the unmanaged data as managed objects with a nice and accessible interface.The ISAPI ConnectionISAPI is a l

13、ow level unmanged Win32 API. The interfaces defined by the ISAPI spec are very simplistic and optimized for performance. They are very low level dealing with raw pointers and function pointer tables for callbacks - but they provide he lowest and most performance oriented interface that developers an

14、d tool vendors can use to hook into IIS. Because ISAPI is very low level its not well suited for building application level code, and ISAPI tends to be used primarily as a bridge interface to provide Application Server type functionality to higher level tools. For example, ASP and ASP.NET both are l

15、ayered on top of ISAPI as is Cold Fusion, most Perl, PHP and JSP implementations running on IIS as well as many third party solutions such as my own Web Connection framework for Visual FoxPro. ISAPI is an excellent tool to provide the high performance plumbing interface to higher level applications,

16、 which can then abstract the information that ISAPI provides. In ASP and ASP.NET, the engines abstract the information provided by the ISAPI interface in the form of objects like Request and Response that read their content out of the ISAPI request information. Think of ISAPI as the plumbing. For AS

17、P.NET the ISAPI dll is very lean and acts merely as a routing mechanism to pipe the inbound request into the ASP.NET runtime. All the heavy lifting and processing, and even the request thread management happens inside of the ASP.NET engine and your code.As a protocol ISAPI supports both ISAPI extens

18、ions and ISAPI Filters. Extensions are a request handling interface and provide the logic to handle input and output with the Web Server its essentially a transaction interface. ASP and ASP.NET are implemented as ISAPI extensions. ISAPI filters are hook interfaces that allow the ability to look at E

19、VERY request that comes into IIS and to modify the content or change the behavior of functionalities like Authentication. Incidentally ASP.NET maps ISAPI-like functionality via two concepts: Http Handlers (extensions) and Http Modules (filters). Well look at these later in more detail. ISAPI is the

20、initial code point that marks the beginning of an ASP.NET request. ASP.NET maps various extensions to its ISAPI extension which lives in the .NET Framework directory:本文摘自http:/www.west-译文1从底层了解ASP.NET的结构 摘要ASP.NET是一个用于构建Web程序的强大平台,提供了强大的柔性和能力以至于它可以构建任意的Web程序。许多人仅仅对处于ASP.NET高层次的框架如:WebForms和WebServic

21、es比较熟悉,因此,在这篇文章里,我将会阐述有关ASP.NET比较底层的知识,并且将会解释,如何将请求从Web Server移交给ASP.NET运行时,然后通过ASP.NET HTTP管道处理这些请求。1 ASP.NET是什么?我们从最简单的定义开始,ASP.NET是什么?我通常喜欢用如下语句来描述ASP.NET。ASP.NET是完全使用托管代码处理Web请求的一个成熟引擎平台。它不仅仅只是WebForms和WebServices。ASP.NET是一个请求处理引擎。它获取客户端请求,然后通过它内置的管道,把请求传到一个终点,在这个终点,开发者可以添加处理这个请求的逻辑代码。实际上这个引擎和HT

22、TP或者Web Server是完全分开的。事实上,HTTP运行时是一个组件,你可以把它宿主在IIS之外的应用程序上。甚至完全可以和其它的服务组合在一起。通过使用内置的管道路由请求,HTTP运行时提供了一套复杂的,但却很优雅的机制。在处理请求的每一个层面都牵涉到许多对象,但大多数对象都可以通过派生或者事件接口来扩展。所以,此框架具有非常高的可扩展性。通过这一套机制,可以进入较低层次的接口如:缓存,身份验证,授权等是有可能的。你可以在处理请求之前或之后过滤内容,或者仅仅把匹配指定签名的客户端请求直接路由到你的代码里或转向其它的URL。针对同一件事情,可以通过不同的处理方法完成,而且实现代码都非常的

23、直观。除此之外,在容易开发和性能之间,HTTP运行时还提供了最佳的灵活性。整个ASP.NET引擎完全构建在托管代码里,所有的扩展性功能都是通过托管代码的扩展提供。对于功能强大的.NET框架而言,使用自己的东西,构建一个成熟的、高性能的引擎体系结构已经成为一个遗嘱。尽管如此,但重要的是,ASP.NET给人印象最深的是高瞻远瞩的设计,这使得在其之上的工作变得非常容易,并且提供了几乎可以钩住请求处理当中任意部分的能力。使用ASP.NET可以完成一些任务,之前这些任务是使用IIS上的ISAPI扩展和过滤来完成的。尽管还有一些限制,但与ASP相比,已经有了很大的进步。ISAPI是底层Win32样式的AP

24、I,仅它的接口就有1兆,这对于大型的程序开发是非常困难的。由于ISAPI是底层的接口,因此它的速度也是非常的快。但对于企业级的程序开发是相当的难于管理的。所以,在一定的时间内,ISAPI主要充当其它应用程序或平台的桥接口。但是无论如何,ISAPI没有被废弃。事实上,微软平台上的ASP.NET和IIS的接口是通过宿主在.NET里的ISAPI扩展来通信的,然后直达ASP.NET运行时。ISAPI提供了与Web Server通信的核心接口,然后ASP.NET使用非托管代码获取请求以及对客户端请求发出响应。ISAPI提供的内容经由公共对象类似于HttpRequest和HttpResponse,通过一个

25、设计优良的、可访问的接口,以托管对象的方式暴露非托管数据。2 从浏览器到ASP.NET让我们从一个典型的ASP.NET Web请求的生命周期的起点开始。用户通过在浏览器中键入一个URL,点击一个超链接,提交一个HTML表单(一个post请求),或者一个客户端程序调用基于ASP.NET的WebService(通过ASP.NET提供服务)。在服务器端,IIS5或者IIS6将会收到这个请求。ASP.NET的底层通过ISAPI扩展与IIS通信,然后,通过ASP.NET,这个请求通常被路由到一个带有.aspx扩展名的页面。但是,这个处理过程如何工作,则完全依赖于HTTP处理器(handler)的执行。这

26、个处理器将被安装用于处理指定的扩展。在IIS中,.aspx经由“应用程序扩展”被映射到ASP.NET ISAPI的dll文件:aspnet_isapi.dll。每一个触发ASP.NET的请求,都必须经由一个已经注册的,并且指向aspnet_isapi.dll的扩展名来标识。注:ISAPI是自定义Web请求处理中第一个并且具有最高性能的IIS入口点。依靠扩展名,ASP.NET把一个请求路由到一个恰当的处理器,该处理器则负责处理这个请求。举个例子,WebServices的扩展名.asmx不会把一个请求路由到磁盘上的某一个页面,而是会路由到在定义中附加了指定特性(WebMethodAttribute

27、)的类,此特性会把它标识成一个Web Services的实现。许多其它的处理器将随着ASP.NET一起被安装。当然也可以定义你自己的处理器。在IIS里所有的HttpHandler被映射并指向ASP.NET ISAPI扩展,并且这些HttpHandler也都在web.config里配置,用于把请求路由到指定的HTTP处理器里执行。每一个处理器都是一个.NET类,用于处理指定的扩展。而这些处理器可以处理简单到只有几行代码的Hello World,也可以处理复杂到类似ASP.NET的页面以及执行WebService。就目前而言,仅仅需要理解扩展就是一种基本的映射机制,ASP.NET用它可以从ISAP

28、I里获取一个请求,然后把请求路由到指定处理该请求的处理器中。原文2 Thirteen ASP.NET MVC extensibility points you have to knowAbstractOne of the main design principles ASP.NET MVC has been designed with is extensibility. Everything (or most of) in the processing pipeline is replaceable so, if you dont like the conventions (or lack o

29、f them) that ASP.NET MVC uses, you can create your own services to support your conventions and inject them into the main pipeline.In this post Im going to show 13 extensibility points that every ASP.NET MVC developer should know, starting from the beginning of the pipeline and going forward till th

30、e rendering of the view.1. RouteConstraintUsually you could put some constrains on url parameters using regular expressions, but if your constrains depend on something that is not only about the single parameter, you can implement the IRouteConstrainss method and put your validation logic in it.One

31、example of this is the validation of a date: imagine an url that has year, month and date on different url tokens, and you want to be able to validate that the three parts make a valid date.2. RouteHandlerNot really specific to ASP.NET MVC, the RouteHandler is the component that decide what to do af

32、ter the route has been selected. Obviously if you change the RouteHandler you end up handling the request without ASP.NET MVC, but this can be useful if you want to handle a route directly with some specific HttpHanlders or even with a classic WebForm.3. ControllerFactoryThe controller factory is th

33、e component that, based on the route, chooses which controller to instantiate and instantiate it. The default factory looks for anything that implements IController and whose name ends with Controller, and than create an instance of it through reflection, using the parameter-less constructor. But if

34、 you want to use Dependency Injection you cannot use it, and you have to use a IoC aware controller factory: there are already controller factory for most of the IoC containers. You can find them in MvcContrib or having a look at the Ninject Controller Factory.4. ActionInvokerActionInvoker is respon

35、sible for invoking the action based on its name. The default action invoker looks for the action based on the method name, the action name and possibly other selector attributes. Then it invokes the action method together with any filter defined and finally it executes the action result.If you read

36、carefully you probably understood that most of the execution pipeline is inside the logic of the default ControllerActionInvoker class. So if you want to change any of these conventions, from the action methods selection logic, to the way http parameters are mapped to action parameters, to the way f

37、ilters are chosen and executed, you have to extend that class and override the method you want to change.A good example of this, is the NinjectActionInvoker I developed to allow injection of dependencies inside filters.5. ActionMethodSelectorAttributeActions, with the default action invoker, are sel

38、ected based on their name, but you can finer tune the selection of actions implementing your own Method Selector. The framework already comes with the AcceptVerbs attribute that allows you to specify to which HTTP Verb an action has to respond to.A possible scenario for a custom selector attribute i

39、s if you want to choose one action or another based on languages supported by the browser or based on the type of browser, for example whether it is a mobile browser or a desktop browser.6. AuthorizationFilterThese kind of filters are executed before the action is executed, and their role is to make

40、 sure the request is “valid”.There are already a few Authorization filters inside the framework, the most “famous” of which is the Authorize attribute that checks whether the current user is allowed to execute the action. Another is the the ValidateAntiForgeryToken that prevents CSRF attacks. If you

41、 want to implement your own authorization schema, the interface you have to implement is IAuthorizationFilter. An example could be the hour of the day.7. ActionFilterAction Filters are executed before and after an action is executed. One of the core filters is the OutputCache filter, but you can fin

42、d many other usages for this filter. This is the most likely extension point you are going to use, as, IMHO, its critical to a good componentization of views: the controller only has to do its main stuff, and all the other data needed by the view must be retrieved from inside action filters.8. Model

43、BinderThe default model binder maps HTTP parameters to action method parameters using their names: a http parameter named user.address.city will be mapped to the City property of the Address object that itself is a property of the method parameter named user. The DefaultModelBinder works also with a

44、rrays, and other list types.But it can be pushed even further: for example you might use it to convert the id of the person directly to the Person object looking up on the database. This approach is explained better in the following post Timothy Khouri (aka SingingEels): Model Binders in ASP.NET MVC

45、. The code is based on the preview 5, but the concept remains the same.9. ControllerBaseAll controllers inherit from the base class Controller. A good way to encapsulate logic or conventions inside your actions is to create you own layer supertype and have all your controllers to inherit from it.10.

46、 ResultFilterLike the ActionFiters, the ResultFilters are execute before and after the ActionResult is executed. Again, the OutputCache filter is an example of a ResultFilter. The usual example that is done to explain this filter is logging. If you want to log that a page has been returned to the us

47、er, you can write a custom RenderFilter that logs after the ActionResult has been executed.11. ActionResultASP.NET MVC comes with many different kind of results to render views, to render JSON, plain text, files and to redirect to other actions. But if you need some different kind of result you can

48、write your own ActionResult and implement the ExecuteResult method. For example, if you want to send a PDF file as result you could write your own ActionResult that use a PDF library to generate the PDF. Another possible scenario is the RSS feed: read more about how to write a RssResult in this post

49、.Look at implementing a custom action result when the only peculiarity is how the result is returned to the user.12. ViewEngineProbably you are not going to write your own view engine, but there are a few that you might consider using instead of the default WebForm view engine. The most interesting one, IMHO, is Spark.But if

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号