It has been nearly four months since the official release of asp.net mvc 1.0. I think there are more and more people familiar with asp.net mvc. I plan to write some text about how to deploy asp.net mvc.
The content includes IIS version changes and asp.net Working principles.
The things involved are relatively basic and have a lot of content. There will certainly be things we already know, but for integrity, it may be divided into one) and two )...... If you are not familiar with asp.net, you may encounter some things that you cannot understand. In these cases, I will provide books or garden friends articles that you are recommended to read for your reference, if you are a senior asp.net developer, you can skip this step.
References: Pro asp.net mvc Framework.pdf, which can be searched and downloaded)
Deployment means to publish your website to the server for practical use. If you have deployed the asp.net project, you will find that the deployment of asp.net mvc is actually similar to the deployment of asp.net. The only special thing is that asp.net mvc uses Routing, someone may have tried to use a URL without a suffix on IIS6. If you know the content listed below, it will become very easy.
The conditions required by the asp.net mvc host server.
In the request processing architecture of IIS, how is a route integrated with it.
Install IIS6 and 7 on the Windows Server and deploy the asp.net mvc project on them.
Configure your asp.net mvc project.
This article contains the first two contents
Server environment for ASP. net mvc project deployment
To run the asp.net mvc project, our server must meet the following requirements:
IIS5.1 or later versions of IIS, And the asp.net service is enabled.
. NET Framework 3.5 it is best to install SP1 at the same time)
The recommended operating systems are Windows server 2003IIS6 and Windows server 2008IIS7 ). Asp.net mvc does not require the server to install it. Because we set System. web. mvc. dll and Microsoft. web. mvc. dll can be directly deployed in the \ Bin folder. This deployment method is called Private deployment. If the space you bought is not installed with asp.net mvc, the above two dll files are not available in GAC) it is also easy to use private deployment, and if your server has not been installed. NET Framework SP1, you also need. web. abstractions. dll and System. web. routing. dll is also copied to your \ Bin folder. These are described in detail below.
What are the requirements of asp.net mvc for the virtual server we bought?
There are no requirements except that the server must support asp.net 2.0 and. NET Frameworkd 3.5. Therefore, we cannot see any space provider advertising that our space supports asp.net mvc, because by placing the relevant Assembly in the \ Bin folder, you can also privately deploy your asp.net mvc project.
If your server provides IIS7 for commercial use, the IIS7 and asp.net integrated pipeline mode can bring you a clean URL without a suffix. If it is IIS6, it can also be done, however, it is not as efficient, convenient, and easy as IIS7. The content about Windows server 2003/iis6.
About IIS version changes
IIS6/Windows Server 2003.
IIS7/Windows Server 2008.
IIS 7.5/Windows Server 2008 R2 has not been released ).
We will only introduce IIS versions later than 6.0. Next we will quickly cover the knowledge of IIS, including virtual paths, binding settings, and application pools. Finally, let's talk about how IIS processes the requested IIS7 and the URLs without suffixes ).
Understanding websites and virtual directories
IIS can host multiple different websites at the same time. we specify a root directory for each website. This directory can be the local directory of the server or elsewhere on the network, then IIS can find or obtain the static or dynamic request content from the directories it manages.
To instruct specific HTTP requests to the corresponding website, IIS allows us to configure "binding ". The so-called "binding" means to map a specific IP address, TCP port number, and HTTP host name to a specific website. For example:
As an additional configuration, you can also add virtual directories at any level in the website directory folder, each virtual directory indicates that IIS will extract or obtain content from other places and return it to the request for this virtual directory, it depends on the location of the folder specified by the virtual directory you created. It can also be located on the local machine or elsewhere on the network ). The purpose of a virtual directory is to disassociate the location of a real file from the list of website directories. It is similar to the folder's "shortcut ", the existence of virtual directories makes the outside world unaware of the specific location of our real files. I personally feel that the logical meaning is greater than the security significance.
Description: displays virtual directories in IIS7/IIS7.5.
For each virtual directory, you can also choose whether to assign it an independent application status. If this option is selected, the independent application corresponding to the virtual directory has its own independent configuration file. If this independent application is an asp.net application, the state of the application is independent of the State of its parent application. Obviously, because they are independent applications, the asp.net running in this virtual directory set to an independent application can be asp.net of a different version than the parent version.
IIS introduced application pool application pools from IIS6 ). The application pool is used to isolate multiple applications running simultaneously on the same server. Each application pool works in an independent working process and sets the maximum memory and CPU usage, process recovery schedule, and so on. Each website or virtual directory application set as an independent application will be allocated to one of the pool of the created IIS application pool. In general, each application should establish an application pool instead of sharing it with other applications. This ensures that if an application crashes, the normal operation of other applications is not affected. Reference: application pool
Bind the website to the Host Name, IP address, and Port
Because the same server can host multiple websites, a system is required to distribute requests to the correct Web application. As mentioned above, we can bind one or more websites:
IP addresses only when the server has multiple IP addresses-for example, multiple network adapters)
For host names and IP addresses, you can choose not to specify anything, not to specify anything, and so on. In this way, all requests that do not match a specific website will be matched to it. If multiple websites have the same binding settings, only one of them can be available at the same time, and the others are in the stopped status. Otherwise, they will not be unique, right. The virtual directory inherits the binding settings of the parent application.
How does IIS process incoming requests and call asp.net
When IIS assigns a received request to the corresponding website, it needs to decide how to process the request. Does it directly return a static content from the disk, or does it need to call a website application to execute it and dynamically generate content to return it? How does it determine this?
As an asp.net mvc program domain, you need to understand this mechanism of IIS. Not only are asp.net mvc programmers, but asp.net programmers both need to understand this mechanism. asp.net programmers include asp.net mvc programmers) -- At least have a basic understanding; otherwise, you will encounter difficulties in understanding the ing between the request and your route configuration.
IIS version changes: How IIS6 and IIS7 process requests in traditional mode
If you are not using the IIS7 integrated pipeline model, you will be using a traditional pipeline model that returns to iis5. In this mode, IIS can only provide static content and dynamic content with a specific extension, which can be mapped to the corresponding isapi url.
IIS analyzes the recent request URL and obtains its extension, for example, http: // hostname/folder/file. aspx? Foo = bar extension is. aspx), which is sent to the corresponding ISAPI extension. For IIS6 and IIS7, you can configure the ing between the ISAPI extension and the extension. For IIS7, you can also use the processor ing Configuration tool to install IIS without the Chinese version, handler Mappings configuration tool), as shown in.
*. Aspx is configured to aspnet_isapi.dll, and aspnent_isapi.dll is loaded to the memory by IIS when the operating system starts, the dll interacts with the hosted environment and then transfers control to the isolated application domain where the application is located. net clr, after the CLR receives control, it instantiates an HttpRuntime class object, and then calls the ProcessRequest method of the HttpRuntime instance object to drive subsequent processing, when the execution of ProcessRequest ends, the Datacontext instance that encapsulates the request context information is constructed and continues. The pipeline may be better when you enter asp.net, and the pipeline is translated on MSDN ), this pipeline is like a workshop assembly line in a factory, and the processing object on this assembly line is the DataContext instance object that encapsulates the request context information instantiated by HttpRuntime, each HTTP module and the backend HTTP processing program of the MPs queue It is a processing process. Some of these processes are responsible for verification permissions, some are responsible for asp.net status management, etc. I think this process is uncertain due to the responsibility chain mode C: \ Windows \ Microsoft.
Note: The Http module implements the IHttpModule interface class, And the Http processing program implements the IHttpHandler interface class. Lao Zhao said: If you do not understand the Http module and Http processing program, you cannot be truly familiar with asp.net, the reason why we need to understand HttpModule and HttpHandler is that after understanding them, we can clearly program based on HttpModule and HttpHandler. This may not be the case if we extend the content in our asp.net application pipeline, this should be the case ). If you want to know about HttpModule and HttpHandler, we recommend two books: both the asp.net 3.5 Technical insider and the asp.net 2.0 advanced programming of server controls and components of Wrox have a good introduction to this topic. Reading the asp.net internal mechanism series or Zhang Ziyang's articles on asp.net is also a good choice. Asp.net mvc is exactly the same as the original asp.net at the HttpModule and HttpHandler levels.
How asp.net is associated
After you install. when the NET framework' wait worker executes aspnet_regiis.exe), the installer automatically registers *. aspx ,*. axd ,*. ashx, and some other extensions to a special ISAPI extension called aspnet_isapi.dll. A request must match a registered extension name, and IIS will activate aspnet_isapi.dll. the unmanaged dll then transfers control to the managed code, and the next step is the time for hosting the code ,. net clr executes the subsequent unmanaged code in a different process.
No suffix URL
Traditionally, the system is normal for the asp.net Server Pages, because they correspond to the actual existence of files suffixed with. aspx and the disk. However, this is not the case for the new routing system. For routing, URLs do not need to correspond to real files on the disk, or even have extensions.
This new URL routing system is created as a. net http module. This HTTP module is created for processing all requests, this module determines whether the control of a request can be transferred to a controller of your asp.net mvc project and received by the Controller. However, this is. NET-managed code. Therefore, requests can be performed only when the request can activate asp.net. For example, IIS maps requests to aspnet_isapi.dll ). Therefore, aspnet_isapi.dll will not be activated unless the request URL has a proper extension. This means that IIS will use this request as a static request to try to return the content of the static file corresponding to the URL, because this static file does Not exist on the disk, we will get the 404 Not Found error. How can I use a URL without an extension! Most of us who want to deploy the asp.net mvc project to IIS6 will encounter this problem. In the following text, we will provide four solutions for you to choose from.
This article mainly introduces the deployment of the asp.net mvc project and the changes of the IIS version.
- Application of session storage mode in ASP. NET
- Set of methods for uploading and downloading files in ASP. NET
- Introduction to cookie read/write methods in ASP. NET
- Introduction and implementation of Single Sign-On in ASP. NET2.0