Original Source – http://www.asp.net/whitepapers/aspnet4
PDF – Download This Whitepaper
Following are few of the important and interesting findings from the above article; there are tons of new features that might of an interest to you. Don’t forget to check out the source article.
Web.Config File Refactoring
Bulk of the content in a web.config have been moved to machine.config hence allowing the web.config in the applications to be literally empty if needed.
Auto-Start Web Applications
- A new scalability feature named auto-start available when ASP.NET 4 runs on IIS 7.5 on Windows Server 2008 R2
- It is a controlled approach for starting up an application pool, initializing an ASP.NET application, and then accepting HTTP request
- “Application Initialization Module” – aka “Application Warm-up Module”
- Helps administrators improve the responsiveness of the web applications by loading them before the first request arrive
- This comes built-in IIS 8.0
Permanently Redirecting a Page
- Instead of using Response.Redirect (which issues HTTP 302 Found) for handling incoming requests to old/stale URLs, use RedirectPermanent (which issues an HTTP 301 Moved Permanently). The later method causes the search engines to store the new URL associated with the content.
Shrinking Session State
- Session state that is stored across a web-farm could be stored either in session-state service or in SQL Server
- Since the Session is stored on remote servers hence storing large session state across network or machine boundaries could take some time
- With ASP.NET 4.0 we now have an option to enable compression on the session state hence reducing the size of the state that needs to be stored and retrieved
- <sessionState> now supports an attribute named compressionEnabled; which if set to “true” will enable ASP.NET to use System.IO.Compression.GZipStream class to compress the session state
Expanding the Range of Allowable URLs
Version prior to ASP.NET 4.0 constrained the length of the URL path to 260 characters. Not any more! With ASP.NET 4.0 you may increase or decrease the limit as you like by setting the following two <httpRuntime> attributes: maxRequestPathLength and maxQueryStringLength
maxRequestPathLength controls the portion of the URL that doesn’t include protocol, server name, and query string)
maxQueryStringLength controls the length of the query string
Extensible Request Validation
ASP.NET provides request validation checks whether help against the XSS attacks. But sometimes that validation results in too many false positives. Application developers or system administrators had no control over the validation rules resulting in unexpected behavior at times.
With ASP.NET 4.0 the developers can now implement their own request validation logic and plug that into the ASP.NET pipeline! It is a three step process:
- Implement a class that derives from RequestValidator class
- Override the IsValidRequestString method
- Configure the requestValidationType attribute on the <httpRuntime>
Object Caching and Object Caching Extensibility
We all know and love ASP.NET Caching which is provided under the System.Web.Caching namespace. It is so popular that non-web application developers want to use it in their desktop application! It is awkward to say the least to use a web dependent implementation in a Windows desktop application for example.
To address this issue and to make Caching available to non-web applications, .NET 4.0 introduced a brand new implementation of caching which is part of the System.Runtime.Caching namespace (System.Runtime.Caching.dll assembly).
The new MemoryCache class is closely modeled on the ASP.NET Cache hence you will find similar concepts and implementation.
Extensible HTML, URL and HTTP Header Encoding
You may now create custom encoder which ASP.NET will use for the following text-encoding tasks:
- HTML encoding
- URL encoding
- HTML attribute encoding
- Encoding outbound HTTP headers
Simply derive a class from System.Web.Util.HttpEncoder and configure it in the httpRuntime section of the web.config file.
Routing in ASP.NET 4
ASP.NET 4 has built-in support for routing with web forms, hence allowing you to configure an application to accept request URLs that don’t map to physical files.
Use the RouteTable.Routes.MapPageRoute method to define a web form route.
With ASP.NET 4.0, you could also use the PageRouteHandler class for mapping routes to appropriate web forms. The following example is equivalent of the above example.
You can use one of the following two properties to get your hands on the data that the routing framework extracted from the URL.
HttpRequest.RequestContext.RouteData and Page.RouteData
Setting Client IDs
With ASP.NET 4.0, the developers have more control over client id generation. The new ClientIDMode property lets you specify how the client ID is generated for controls.
AutoID – Same behavior as earlier versions of ASP.NET – use default algorithm for generating id
Static – This ensures that whatever id developer has provided for the control remains as it is! It is your responsibility to ensure that the control ids are unique.
Predictable – This option is primarily used in data controls that use repeating controls. It concatenates the ID properties of the control’s naming containers, but generated client ID values don’t contain strings like “ctlxxx”.
Inherit – This setting is the default for controls; it specifies that a control’s ID generation is the same as its parent.
This property could be set both at the Page level or the control level.
Setting this property at the Page level defines default value for all controls in the current page. The default Page level value for this property is AutoID. The default control level value for this property is Inherit.
Therefore if you don’t specify this property anywhere in the code, it defaults to AutoID for every control hence exhibiting same behavior as earlier versions of ASP.NET.
This property can also be set at the computer-level or at the application level!