HostingEnvironment and host environment, hostingenvironment

Source: Internet
Author: User
Tags configuration settings one more line

HostingEnvironment and host environment, hostingenvironment

Defines the configuration settings used to control the behavior of the application host environment.

The configuration is as follows:

 

ShadowCopyBinAssemblies: This value indicates whether the application assembly in the Bin directory is copied to the ASP. NET temporary file directory of the application. However, I am confused when I look at this sentence. Fortunately, I have read a foreigner's article and learned its role through my own practice. When we update the content of the bin folder, it takes effect without restarting the website. The reason is ASP. NET monitors the bin folder. When the bin folder is found, the website will be updated immediately. This function is controlled by shadowCopyBinAssemblies. If it is set to false, when the website is running, the files in the bin folder will be locked and cannot be updated at any time, not to mention taking effect immediately. This setting is used in scenarios where too much binfile content is updated, which affects the website performance.

IdleTimeout: set the time before uninstalling an inactive application. The format is HH: MM: SS or "unlimited ". The default value is "Infinite ". However, the format is not correct because, for example

The set value is actually an int value in minutes. This idelTimeout feature is used to disable the appdomain with the idle time reaching the set value in minutes. Therefore, I did an experiment on purpose.

Add code to Global. asax to monitor the time and cause of Application shutdown.

protected void Application_End(){File.AppendAllText(@"E:\Application_End.txt",string.Format("{0}\t{1}\r\n",System.Web.Hosting.HostingEnvironment.ShutdownReason.ToString(),DateTime.Now) );}

In addition, a cache is added to the Action method, and the cache is encapsulated. The cache uses myappdomainTest as the key value to cache the value. If there is no cache, the delegate is executed and the result is cached, function: See the results later.

object now = CacheHelper.GetFromCache<object>("myappdomainTest", () =>{System.IO.File.AppendAllText(@"E:\Application_End.txt", string.Format("write cache myappdomainTest {0}\r\n",DateTime.Now));return DateTime.Now;});

Output The AppDomain information in the View in the form of a pop-up window to prove that he has been replaced

<script>$(function () {alert('@AppDomain.CurrentDomain.GetHashCode();');});</script>

Add

After accessing the page, the HashCode of appdomian is as follows:

The output file is as follows:

Wait for 6 minutes, because it is idle for 5 minutes, so it is assumed that the current time is, idle for 5 minutes is required to reach.

Let's look at the output file with one more line.

It indicates that the AppDomain was recycled at, and the webpage was accessed again.

It is found that the AppDomain is different. Then, let's look at the output file.

The cache is no longer available and needs to be generated again.

If idleTimeout = "5" is removed, the AppDomain will not be recycled all the time. After accessing the site, no matter how long it is idle, Application_End will not be triggered

ShutdownTimeout: set the time (in seconds) when the reference program is closed normally ). I cannot understand this passage, and I cannot find relevant information on the Internet. I first looked at the source code and initiateshudownworkitemcallback (Object state/* not used */) IN THE HostingEnvironment private method */) find this section, and the following shutdonwTimeoutSeconds is the shutdownTimeout set in the configuration.

Later, I realized it was a feature. It means that in the process of shutting down an application, I had to go through a time process with so many seconds of shutdownTimeoutSeconds. So I was excited and tried to call the HostingEnvironment. initiateshudown () method, similar to the idleTimeout test above.

The difference is two seconds. These two seconds are far from the configured values. Later I noticed that another condition for sleep is that the element of the _ registeredObjects set must be greater than 0, is there no element in this set? This registeredObjects is

The HostingEnvironment. initiateshudown () method is used to close the Web application associated with the host and remove the registered object from the system. ShutdownTimeout is set to ensure that there is enough time to cancel the registered IRegisteredObject object when it is disabled. Unfortunately, there is no way to identify it.

The above is only my inference. If you have better opinions or opinions, please criticize and correct them. The following is the fragmented content about idleTimeout and ShutdownTimeout found on the Internet.

Difference between idleTimeout and ShutdownTimeout in stackoverflow

Description of idleTimeout in WCF

After modifying. svc file, the application domain is also recycled. the hosting environment will try to close all the WCF services 'open connections gracefully in a timely manner. when services somehow don't close in time, they will be forced to abort. throughHostingEnvironmentSettingsConfiguration settings, you can influence the behavior of reconfiguring, as you can see in Listing 5-8.IdleTimeoutSetting determines the amount of idle time in seconds for an application domain to be recycled.ShutdowntimeoutSetting determines the amount of time in seconds to gracefully shut down an application. After this time-out, it forces applications to shut down.

Listing 5-8. Web. config with hostingenvironment section for reconfiguring settings

<System. web>
<HostingEnvironment idleTimeout = "20"
ShutdownTimeout = "30"/>
</System. web>

When you are using WCF sessions, these reconfiguring features are critical to understand. this is typically the case in the security and reliable messaging scenarios, as you will read in Chapters 6 and 8 of this book. by default, WCF stores session state in memory. this is a different implementation from ASP. NET session state and doesn' t come with a configuration to switch over to persistent session state storage. however, you can, and shoshould, in the security and reliable messaging scenarios benefit from the ASP. NET implementation. using the ASP. NET compatibility features of WCF provides you with the SQL Server and state server implementations of ASP. NET session state to support enterprise-ready scenarios. in the next section, you will learn how to benefit from the wcf asp. NET compatibility mode.

From https://msdn.microsoft.com/en-us/library/bb332338.aspx>

The following is the translation

After the. svc file is modified, the application domain will be recycled. The bearer environment will try to close all open connections of the WCF Service on time and normally. If the service cannot be closed on time for some reason, the system will force them to stop. The HostingEnvironmentSettings configuration can affect the collection behavior, as shown in Figure 5-8. The idleTimeout setting determines the idle time (in seconds) before the application domain is recycled ). Shutdowntimeout determines the length of time (in seconds) before the application is shut down normally ). When this timeout occurs, it forces the application to close.

It is important to understand these collection functions when using a WCF session. This is often the case in secure and reliable messaging scenarios, which will be described in Chapter 1 and Chapter 2 of this book. By default, WCF stores the session Status in the memory. This is different from ASP. NET session status. It does not need to be configured to switch to persistent session Status storage. However, in the secure and reliable message solution, you can and should benefit from ASP. NET implementation. By using the ASP. NET compatibility feature of WCF, you can obtain SQL Server and status Server implementations of ASP. NET session statuses to support enterprise-available solutions. The next section describes how to benefit from the wcf asp. NET compatibility mode.

A description of hostingEnvironment in Programming Microsoft ASP. NET 4.

In addition, the HostingEnvironment class seen in MSDN does not have many associations with the surface of this configuration section. After reading the source code, I found that some attributes in the section still use the content of the configuration section, several useful attributes are also found.

For example, some people are worried about getting the path of the current website. In fact, you can also use the Server ath of the Server attribute.

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.