SharePoint basics 6-ASP. NET architecture involved in SharePoint infrastructure

Source: Internet
Author: User

ASP. net Framework represents an important productivity layer on the IIS and ISAPI programming models. if you are familiar with ASP. NET development, you will know that it provides convenience for compiling managed code for your application logic, such as C #, VB. and allows you to work in a productivity-oriented visual editor provided by Microsoft Visual Studio. ASP. the. NET Framework also provides many other valuable abstractions to help developers perform status management, data binding, navigation, and data caching.

 

ASP. NET framework is implemented by an ISAPI extension called aspnet_isapi.dll. ASP. net basic configuration involves: At the IIS Site or virtual directory level, Asp. net file suffix registration ing application, Asp.. Net file suffixes include. aspx ,. ascx, and. asmx. when IIS sees a request pointing to these file types, it will send the request to aspnet_isapi.dll for processing. This dll will efficiently transfer the control to ASP.. NET Framework. so, Asp. the method by which the Net Framework processes a request depends largely on the file type (Extension) of the target file ).

 

ASP. net Framework is like an independent ASP. the. NET application executes requests to the IIS Site and virtual directory in the same way. in every ASP. NET application, there is a root directory containing a bunch of files. this architecture ensures ASP.. NET application deployment is a very simple X-copy style. you can create a new virtual directory on the Web server and copy your asp.. NET application file to the root directory. of course, it is a little troublesome to create a virtual directory in the web environment, and then deploy the same file on all the front-end servers on the site.

 

Each ASP.. NET applications can be configured independently in the root directory of the application. config file. web. config is an XML-based file that contains many elements to control ASP. NET framework, such as compiling, page rendering, and status control. A simple web. the config file looks like the following:

<?xml version="1.0" encoding="utf-8" ?><configuration>  <system.web>    <customErrors mode="On" />    

Notes ASP. net Framework is running every ASP.. NET applications are isolated to a certain extent. even if you have configured multiple ASP.. NET applications are also isolated when they are running in the same IIS application pool. ASP.. NET Framework provides multiple ASP instances running in the same IIS worker process.. NET applications are isolated by loading them separately.. NET Framework appdomain. [STUDENT Note: For appdomain information, refer to the article. net appdomain]

 

ASP. NET page

==============

The page is ASP. net Framework is one of the most valuable abstractions. developers construct ASP. NET applications, the most typical way is to drag the server control on the visual design interface of Visual Studio, and modify the properties of pages and controls through standard property sheets. ASP. the. NET Framework and Visual Studio make it easier to add processing logic to the page, to achieve this goal, you can write managed code in response events at the page level and in control-level events.

 

On the physical layer, Asp. A page in the. NET application is. files stored on the Web server end with the aspx suffix are compiled into a DLL file when it is requested by the client. consider the following ASPX page definition, which contains a server-side control and a simple event handler.

<%@ Page Language="C#" %><script runat="server">  protected override void OnLoad(EventArgs e) {    lblDisplay.Text = "Hello, ASP.NET";  }</script>

In the background, Asp. net Framework has done a lot of work. the aspx file is compiled into a DLL file. first, it must first parse the aspx file and generate a C # (or VB.. net). The source file contains a public class inherited from the page class. The page class is defined in system. web. in the UI namespace, it exists in system. web. DLL. when ASP. when the net page parser generates this class that inherits from the page, it establishes a control tree structure, including all the server-side controls defined in the page. the page parser also adds the required code to hook up any event handlers defined on the page.

 

Once ASP. NET page parser built. aspx source file, it starts to compile this source file to become a DLL. this compilation automatically occurs in this. when the ASPX page is requested for the first time. once ASP.. Net compiled the DLL of the aspx file, and a copy of the DLL will be used to serve all subsequent requests pointing to the same aspx file. however, Asp. net will monitor the DLL timestamp during runtime. if it finds that the aspx file associated with the DLL has been updated, it will re-compile to recreate the DLL.

 

ASP. one of the reasons why the Net Framework is so popular is that it facilitates server-side controls. use with ASP.. NET framework together with release, it is very easy to create pages with out-of-box controls. there are many controls, such as the validation control, the calendar control, and controls that support data binding, such as the gridview control and the Repeater control. in addition, it is relatively easy for developers to create custom controls and use them on pages.

 

Master page

======================

ASP. NET 2.0 introduces the master page, which provides a very efficient way to create page templates. in particular, a master page defines general elements that can be used between many different pages (for example, top banner of the Top Banner) and site navigation controls. the layout defined on the master page can be used by many pages linked to this master page. in ASP. in net technology, a page linked to a master page is called content page ). the figure below shows the basic relationship between the master page and the Content Page:

For example, suppose you want to create a master page to define an HTML layout, which includes a banner at the top of the page. you should create a suffix named. the master file is called default. master. next, you should add a @ master command at the top of the page. then, in the following example, you define the HTML layout of the page and add and name placeholders, as shown in the following example:

<%@ Master %>

 

When you want to create a content page, you should create. aspx file, and then add a @ page command, which includes the masterpagefile attribute. once you decide which placeholder you want to replace on the master page, you define a content element for this replace operation. the following is an example of a simple content page link to a master page. The Code replaces the placeholder named placeholdermain in the master page.

<%@ Page Language="C#" MasterPageFile="~/default.master" %><script runat="server">  protected override void OnLoad(EventArgs e)   {    lblDisplay.Text = "Hello World";  }</script><asp:Content ID="main" Runat="Server" ContentPlaceHolderID="PlaceHolderMain" >  <asp:Label ID="lblDisplay" runat="server" /></asp:Content>

Note: When you create a content page and point to a master page, all the HTML you want to add must be written in the content element pointing to a placeholder name. if you write HTML code or server-side controls outside the content element, the page will not be compiled. however, as you can see in the previous example, you can add a script block outside the content element and add any code you want to add to the script block.

 

When a master page defines a named placeholder, you do not need to always replace it in your content page. because the placeholder with the default content is created on the master page. any content page pointing to that master page will get the default content defined in the master page as long as it does not include the named placeholder. another content page that is connected to the same master page and contains the named placeholder will replace the default content with its own custom content.

Finally, make sure that no matter who you are, as long as you create a master page, you have to decide the name of The placeholder and the default content. this is important when designing the WSS site page, because the content page you create will point to the master page created by the WSS team. in this case, you must learn what placeholder The WSS team defines and what types of content can be replaced.

 

HTTP request Pipeline

======================

ASP. net Framework exposes HTTP request pipeline for developers who want to have a deeper level. he provided developers with control over the ISAPI programming model to some extent. however, when you create a component for the HTTP request pipeline, you can use components such as C # Or VB.. net. you can also use ASP.. Net APIs, which is much easier than simply using the ISAPI programming model.

 

It shows the HTTP request pipeline and three alternative component types: httphandler, httpapplication, and httpmodule. when requests come in, they are queued, assigned to a worker thread, and then processed by interacting with these three component types.

 

 

The final end of any request, as shown in the figure, is the httphandler class, which inherits the ihttphandler interface. as a developer, you can create a custom httphandler component and. add the setting element in config to insert your httphandler to the HTTP request pipeline.

 

HTTP request pipeline has an httpapplication component before httphandler. based on an application range, incoming requests are always routed through httpapplication before arriving at httphandler. therefore, an HTTP application can process any request no matter which httphandler is finally routed. this preprocessing phase is controlled by a series of events defined in httpapplication, such as beginrequest, authenticaterequest, and authorizerequest.

 

ASP. net uses a standard httpapplication object to initialize HTTP request pipeline. however, you can create a global. asax file, put it in ASP.. NET application root directory to replace the standard httpapplication component. for example, you can create a global that looks like the following. asax:

<%@ Application Language="C#" %><script runat="server">  protected void Application_AuthenticateRequest(object sender, EventArgs e) {    // your code goes here for request authentication  }  protected void Application_AuthorizeRequest(object sender, EventArgs e) {    // your code goes here for request authorization  }</script>

 

The third component type that can be replaced by HTTP request pipeline is httpmodule. similar to the httpapplication component, httpmodule is designed to process events defined by the httpapplication class. The processing of these events occurs before the request is sent to any httphandler type. for example, you can create a custom httpmodule component to process the time at the Request level, such as beginrequest, authenticaterequest, and authorizerequest. like httphandler, The httpmodule class is defined through an interface. you can create a class that implements the ihttpmodule interface and. add configuration elements to the config file to insert your httpmodule to the HTTP request pipeline.

 

Since the httpapplication component can be defined as an image. the text file with the asax suffix is as simple as the custom httpmodule component is always compiled by the class in the Assembly DLL. to add a custom httpmodule component to HTTP request pipeline, you have to go to the Web. add entries to the config file.

 

Although the httpapplication and httpmodule components are very similar in what they do, httpmodule contains some notable differences. first, unlike the httpapplication component, you must add only one httpapplication component to an application. For the httpmodule component, there is no limit on the number of items you add. ASP. net web. you can add multiple httpmodule components to the config file. second, the httpmodule component can be set at the machine level. in fact, Asp. net Framework comes with several different httpmodule components, they are automatically configured to operate on the machine, for ASP. NET provides functions such as Windows authentication, Forms authentication, and output cache.

 

The last component we will discuss about HTTP request pipeline is httpcontext. with ASP. net initializes a request and sends it to HTTP request pipeline. It also creates an object using the httpcontext class and uses important context-related information to initialize this object.

 

In terms of time, in ASP. net in HTTP request pipeline any custom code has the opportunity to execute before, httpcontext object has been created, realize this is very important. this means that you can always use the httpcontext object and its sub-objects for programming, such as request, user, and response. whenever you develop a component to run in HTTP request pipeline, you can write code like the following:

HttpContext currentContext = HttpContext.Current;string incomingUrl = currentContext.Request.Url;string currentUser = currentContext.User.Identity.Name;currentContext.Response.Write("Hello world");

 

<Inside Microsoft Windows SharePoint Services 3.0>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.