Cached controls and address mappings for asp.net2.0

Source: Internet
Author: User
Tags config datetime httpcontext new features tostring
Asp.net| Cache | Controls this year, Microsoft has finally released a beta test version of the. NET Framework 2.0 beta and a range of development tools, including the Visual Web Developer 2005 series, which can be found in http:// www.asp.net download). In ASP.net 2.0, many new controls and functions have been introduced, with revolutionary changes compared to the previous ASP.net 1.0 and ASP.net 1.1. This article will briefly describe the two new features: caching capabilities and address mapping capabilities. This article describes these two new features with the. NET Framework 2.0 and the Visual Web Developer.

One substitution cache control

In the. NET version prior to ASP.net 2.0, caching can be introduced, which greatly enhances the performance of your application. But the only thing that's not enough when caching is used, caching is generally used, but in some applications it may be necessary to use caching only for certain control content on the page, while other parts will not use caching, and controls that do not use caching will get the most current content on the server in real time. For example, a Web application, a number of fixed web page information, such as the bottom of the page, copyright information, or some not often updated information, you can use the caching function, but some more real-time information, such as stock price trend chart, you can not use the caching function. In this case, the previous asp.net is more difficult to implement, but in ASP.net 2.0, it can be achieved by simply using the substitution cache control. Here's how to use the substitution control to make some parts of a control not apply caching in a page that uses caching.

Here's a simple example. In this example, there will be two time, one of the time shows that the cache is applied, the cache time is 30 seconds, and the other time does not apply caching, and will get the latest time with each refresh of the page with the following code:

<%@ OutputCache duration= "All" varybyparam= "None"%>
<script runat= "Server" language= "VB"
Sub Page_Load (ByVal sender as Object, ByVal e as System.EventArgs)
Cacheddate.text = DateTime.Now.ToString ()
End Sub

Shared Function Getcurrentdate (ByVal context as HttpContext) as String
Return DateTime.Now.ToString ()
End Function
</script>
<title> Substitution Example </title>
<body>
<form id= "Form1" runat= "Server"
<p> The following time shows that caching is not used </p>
<asp:substitution id= "Substitution1" methodname= "Getcurrentdate" runat= "Server"
</asp:substitution>
The following time display uses the caching function, only after 30 seconds to change:

<asp:label id= "Cacheddatelabel" runat= "Server" > </asp:label>

<asp:button id= "Refresh the page" runat= "text="
</asp:button>
</form>
</body>

The following figure is the result of the run

After you run the program, each time you refresh the page, you will see that there is no control that uses caching, you get the most recent time, and the time control that uses the caching feature, which displays the latest time every 30 seconds, and the rest remains unchanged for the last time it appears.

Note that on this page, the page starts with the <%@ OutputCache duration= "None"%>, which uses caching for the page, but simply dragging a substitution control, Implements some of the features that are not cached. In

<asp:substitution id= "Substitution1"
Methodname= "Getcurrentdate"
Runat= "Server" >

, MethodName calls a method in which content is written without caching, and a string is returned in this method. Note that the method that is invoked in the MethodName in the substitution control must be a static method and that the incoming arguments must be HttpContext.

URL mapping function of asp.net 2.0

In asp.net 2.0, the URL mapping feature is added to the Web.config file. What is the URL mapping feature? For example, for example, the original page of your program is homedefault.aspx, but, you changed its name, to Default.aspx, then, in order to allow users to continue to use Default.aspx access to your Web applications, you can use the URL mapping function. First, in the Web.config file, the syntax for URL mapping is as follows:


In which, when enabled is set to True, URL address mapping is allowed, false if the parameter url1 is not allowed to represent the old URL address, URL2 represents the new destination URL address to map, for example,


The effect is that when a user accesses your Web application using homedefault.aspx, the system automatically maps the address to Default.aspx so that it can be accessed correctly by the user. Such techniques can be useful, such as when a user places your site in a Favorites folder, and when your site is revised or some files are changed, users still have access to your site. Also, if your Web application for security purposes, to hide some of the program's URL, you can do this through the above method, because the user in the browser to see the address is still the old URL, in the example above, is the user in the browser in the address bar see, Is homedefault.aspx, not the new address default.aspx.

These are just two of the many features added to ASP.net 2.0, and Asp,net 2.0 has more new features and mysteries to wait for everyone to dig.



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.