Migrating to ASP.NET 2.0 — Its backward compatible

October 21, 2005

Here are my investigations based on MSDN and a running site at Microsoft since Aug 2005 with better performance than before:

· Because of the way that the .NET Framework is designed, you can deploy the 2.0 framework without disrupting a current installation of the 1.0 or 1.1 frameworks.

To configure a 1.x application’s script map to use the .NET Framework version 2.0

  • On the Start menu, click Run.
  • In the Open box, type inetmgr and click OK.
  • In Internet Information Services (IIS) Manager, expand the local computer, and then expand Web Sites.
  • Select the target Web site that is running in the .NET Framework version 1.x.
  • Right-click the name of the virtual directory for the Web site, and then click Properties.
    The Properties dialog box appears.
  • In the ASP.NET version selection list, choose the .NET Framework version 2.0.
    Click OK.
  • Navigate to a page in your application and confirm that your application runs as expected.

· If you are planning on using ASP.NET 2.0 on a production site, you will need to acquire the Microsoft Visual Studio 2005 Beta 2 Go-Live license (Nov 2005 is the final release of VS .NET 2005, so this may change) http://lab.msdn.microsoft.com/ or http://msdn2.microsoft.com/ . Basically, Microsoft does not offer support for the pre-release products.
· ASP.NET 2.0 and ASP.NET 1.1 Applications can live on the same IIS Server: By default, your 1.x applications will continue to use the 1.x framework. However, you will have to configure your converted/new applications (web sites/virtual directories) to use the 2.0 framework.
· Requirements for hosting ASP.NET 2.0 Apps:
o Internet Information Services (IIS) version 5.0 or later. To access the features of ASP.NET, IIS with the latest security updates must be installed prior to installing the .NET Framework. (So you can run ASP.NET 2.0 apps on old boxes with IIS5-Win 2000 Server)
o ASP.NET is supported only on the following platforms: Microsoft Windows 2000 Professional (Service Pack 3 recommended), Microsoft Windows 2000 Server (Service Pack 3 recommended), Microsoft Windows XP Professional, and Microsoft Windows Server 2003 family.
o Microsoft Data Access Components 2.8; is recommended. This is for applications that use data access.
o Supported Operating Systems: Windows 2000; Windows 98; Windows 98 Second Edition; Windows ME; Windows Server 2003; Windows XP. Make sure you have the latest service pack and critical updates for the version of Windows that you are running. To find recent security updates, visit Windows Update.
o You must also be running Microsoft Internet Explorer 5.01 or later for all installations of the .NET Framework. Install Internet Explorer 6.0 Service Pack 1.

Here’s what we gain:
New Features in ASP.NET 2.0
· Master pages are a new feature introduced in ASP.NET 2.0 to help you reduce development time for Web applications by defining a single location to maintain a consistent look and feel in a site. Master pages allow you to design a template that can be used to generate a common layout for many pages in the application.
· Content pages (I call them business logic sub-pages) are attached to a master-page and define content for any ContentPlaceHolder controls in the master page. The content page contains controls that reference the controls in the master page through the ContentPlaceHolder ID. The content pages and the master page combine to form a single response.
· Nested Master Pages: In certain instances, master pages must be nested to achieve increased control over site layout and style. For example, your company may have a Web site that has a constant header and footer for every page, but your accounting department has a slightly different template than your IT department.
· Overriding Master Pages: Although the goal of master pages is to create a constant look and feel for all of the pages in your application, there may be situations when you need to override certain content on a specific page. To override content in a content page, you can simply use a content control.
· Themes and Skins: ASP.NET 2.0 rectifies the issue of using CSS and inline styles in ASP.NET 1.1 pages, through the use of themes and skins, which are applied uniformly across every page and control in a Web site.A skin is a set of properties and templates that can be used to standardize the size, font, and other characteristics of controls on a page. Themes are similar to CSS style sheets in that both themes and style sheets define a set of common attributes that apply to any page where the theme or style sheet is applied.
· Security: Managing User Info with Profiles and Login Controls: The membership provider and login controls in ASP.NET 2.0 provide a unified way of managing user information. ASP.NET 2.0 offers new login controls to help create and manage user accounts without writing any code.The ASP.NET 2.0 profile features allow you to define, save, and retrieve information associated with any user that visits your Web site. In a traditional ASP application, you would have to develop your own code to gather the data about the user, store it in session during the user’s session, and save it to some persistent data store when the user leaves the Web site.
· Localizaton. Enabling globalization and localization in Web sites today is difficult, requiring large amounts of custom code and resources. ASP.NET 2.0 and Visual Studio 2005 provide tools and infrastructure to easily build Localizable site including the ability to auto-detect incoming locale’s and display the appropriate locale based UI. Visual Studio 2005 includes built-in tools to dynamically generate resource files and localization references. Together, building localized applications becomes a simple and integrated part of the development experience.
· 64-Bit Support. ASP.NET 2.0 is now 64-bit enabled, meaning it can take advantage of the full memory address space of new 64-bit processors and servers. Developers can simply copy existing 32-bit ASP.NET applications onto a 64-bit ASP.NET 2.0 server and have them automatically be JIT compiled and executed as native 64-bit applications (no source code changes or manual re-compile are required).
· Caching Improvements. ASP.NET 2.0 also now includes automatic database server cache invalidation. This powerful and easy-to-use feature allows developers to aggressively output cache database-driven page and partial page content within a site and have ASP.NET automatically invalidate these cache entries and refresh the content whenever the back-end database changes. Developers can now safely cache time-critical content for long periods without worrying about serving visitors stale data.
· Web Parts: Web Parts are modular components that can be included and arranged by the user to create a productive interface that is not cluttered with unnecessary details. The user can:
o Choose which parts to display.
o Configure the parts in any order or arrangement.
o Save the view from one Web session to the next.
o Customize the look of certain Web Parts.
· Better Development Environment: ASP.NET 2.0 continues in the footsteps of ASP.NET 1.x by providing a scalable, extensible, and configurable framework for Web application development. The core architecture of ASP.NET has changed to support a greater variety of options for compilation and deployment. As a developer, you will also notice that many of your primary tasks have been made easier by new controls, new wizards, and new features in Visual Studio 2005. Finally, ASP.NET 2.0 expands the palette of options even further by introducing revolutionary new controls for personalization, themes and skins, and master pages. All of these enhancements build on the ASP.NET 1.1 framework to provide an even better set of options for Web development within the .NET Framework.
· Last but not the least there’s a host of new language features that reduce code lines in .NET 2.0: What’s New in the C# 2.0 Language and Compiler
With the release of Visual Studio 2005, the C# language has been updated to version 2.0, which supports the following new features:
o Generics
Generic types are added to the language to enable programmers to achieve a high level of code reuse and enhanced performance for collection classes. Generic types can differ only by arity. Parameters can also be forced to be specific types. For more information, see Generic Type Parameters.

o Iterators
Iterators make it easier to dictate how a foreach loop will iterate over a collection’s contents.

o Partial Classes
Partial type definitions allow a single type, such as a class, to be split into multiple files. The Visual Studio designer uses this feature to separate its generated code from user code.

o Nullable Types
Nullable types allow a variable to contain a value that is undefined. Nullable types are useful when working with databases and other data structures that may contain elements that contain no specific values.

o Anonymous Methods
It is now possible to pass a block of code as a parameter. Anywhere a delegate is expected, a code block can be used instead: there is no need to define a new method.

o Namespace alias qualifier
The namespace alias qualifier (::) provides more control over accessing namespace members. The global :: alias allows access the root namespace that may be hidden by an entity in your code.

o Static Classes
Static classes are a safe and convenient way of declaring a class containing static methods that cannot be instantiated. In C# version 1.2 you would have defined the class constructor as private to prevent the class being instantiated.

o External Assembly Alias
Reference different versions of the same component, contained in the same assembly, with this expanded use of the extern keyword.

o Property Accessor Accessibility
It is now possible to define different levels of accessibility for the get and set accessors on properties.

o Covariance and Contravariance in Delegates
The method passed to a delegate may now have greater flexibility in its return type and parameters.

o How to: Declare, Instantiate, and Use a Delegate
Method group conversion provides a simplified syntax for declaring delegates.

o Fixed Size Buffers
In an unsafe code block, it is now possible to declare fixed-size structures with embedded arrays.

o Friend Assemblies
Assemblies can provide access to non-public types to other assemblies.

o Inline warning control
The #pragma warning directive may be used to disable and enable certain compiler warnings.

o volatile
The volatile keyword can now be applied to IntPtr and UIntPtr.

Thanks to the various links by Microsoft for the above info.

.NET 2.0 Generics samples & Performance Comparison

January 21, 2005

One of the most awaited features of Microsoft .NET 2.0 is generics. Starting with VS 2005, C#, Managed C++, and VB will have CLR support for generics.

Generics promise to increase type safety, improve performance, reduce code duplication(code reuse) and eliminate unnessecary casts(boxing). The most obvious application of generics in the framework class library are the generic collections in the new System.Collections.Generic namespace.

While Generic types do have a similar syntax to C++ templates, they are instantiated at runtime as opposed to compile time (by Microsoft’s C++ compiler), and they can be reflected on via meta-data. Also, in Generics, member access on the type paramater is verified based on the constraints placed on the type parameter; whereas, in templates, member access is verified on the type argument after instantiation. When the MS C++ compiler creates a separate type for every template specialization, that does not necessarily mean every type emits separate code. In fact, you’ll find that through a feature called COMDAT folding, most templates share quite a bit of code. (Basically, the myth of code bloat for templates isn’t true these days.) By having separate specializations of code at compile-time, the compiler has the ability to optimize each type individually, which includes inlining. If every instance of a function is inlined, the template code is thrown away by the linker resulting in less code. For these reasons, template code is generally much faster and leaner than an equivalent generic alternative.

C++ templates are a compile-time feature much like a macro preprocessor and are thus not a good solution for a highly dynamic language such as C#.

In .NET, for value types, generics is considerably faster, and for reference types, generics is typically comparable in performance—or faster.

Good Links: Introducing Generics in the CLR

Generics Performance Results and a sample to test other collections

Generics Performance (CSharp)

The problem with .NET generics

A generic Set type for .NET

6 questions about generics.

Performance: Interfaces Vs. Inheritance (Abstract Base Classes) Vs. Generics

Thanks to the authors for the above links.

.NET memory and performance improvement

January 17, 2005

Now that you have finished your .NET Application, the memory bogs you down?

Limiting memory usage of .NET applications is a requirement that often arises in programs that allocate and use large amounts of memory. The garbage collected environment that the CLR offers means that memory that is used to perform some calculation then discarded is not immediately collected once it is no longer needed, and application memory usage can become quite high in some situations. Rather than wait for all available memory to be exhausted before performing a full garbage collection, there are scenarios where preserving memory for other processes is a higher priority than the raw speed of the memory-intensive .NET application.

Well, there is a COM API RequestVirtualMemLimit to be called after overriding to prevent your application from hogging all the memory and waiting for the last instant for the GC to start freeing off memory. To the CLR, a failed RequestVirtualMemLimit call will appear the same as Windows running out of memory and returning a NULL pointer for a VirtualAlloc request. Rather than simply refusing to allocate any further memory, a gentler and more effective technique is to allow a small memory increase so exception objects can be successfully created, and an OutOfMemory exception can gracefully thrown and handled by managed code. If memory cannot be allocated for exception objects, the runtime will terminate without giving exception handlers a chance to execute, which will rarely be the desired behaviour.

Therefore, to place an effective cap on memory usage, an object implementing IGCHostControl needs to be provided to the runtime.

But the problem, is the “chicken and egg” problem. The ICorConfiguration interface, which is implemented by CorRuntimeHost, has a method called SetGCHostControl that allows an IGCHostControl-implementing object to be provided to the runtime. Unfortunately, it is not possible to retrieve an ICorConfiguration reference after the runtime has started. The QueryInterface logic of CorRuntimeHost fails throws an error when a request for ICorConfiguration is made, and the ICorRuntimeHost::GetConfiguration method, which returns a ICorConfiguration reference, fails when it is called post-startup. When certain hosting functionality is only available before the runtime is started, it is impossible to use the functionality from managed code. Managed code can never execute before the runtime starts, and if the functionality is required, as it is with the memory capping functions, the only option is to explicitly host the runtime using unmanaged code.
Read on at http://www.dotnetperformance.com/downloads/hosting.doc .
Thanks to the author for this insight into unmanaged code advantages in a managed world.

Looking forward to a better managed C++ in .NET 2.0

.NET Remoting

December 18, 2004

.NET Remoting is gaining a lot of importance so here’s some good links




Thanks to the authors for this info.

UML 2.0

December 13, 2004

UML is a modeling language for specifying, visualizing, constructing, and documenting the artifacts of a system-intensive process



Thanks to the authors for a nice site on UML.

Windows/.NET Event logging (with Internationalization/parameter features in a message file)

November 18, 2004

Event logging pre-.NET
When you access the event log using the standard NT API calls, the system stores a structure that contains (amongst other things) the message ID and any replacement strings (“inserts”) for the message — but it does not store the message text itself.
Reading from the log
When you read an entry from an event log, the system reads the stored message ID and replacement strings, gets the text of the message for the current locale from a MESSAGETABLE resource contained within the file specified in the EventMessageFile key in the registry, inserts the replacement strings, and returns you the formatted string.
As well as keeping the log file small (which improves performance when accessing the event log on a remote machine), just storing the message ID and replacement strings also means that the same message can be viewed in different languages as long as the client:Has the file installed that contains that locales MESSAGETABLE The local registry has been configured to tell NT where to find it The file containing the messages only has to be installed on the machine that is doing the reading and does not have to exist on the one that is doing the writing or the one that holds the log (they can all be different machines).
Event logging with .NET
Under .NET, message sources are registered with the EventMessageFile value always set to EventLogMessages.dll, which is installed in the GAC. This file has 65,535 entries, each of which contain a single string: %1In other words, for every possible event ID the entire format string is a placeholder that takes a single replacement string — which is always the message that you pass to EventLog.WriteEntry()

  • The main drawbacks with this approach are:
    You have the responsibility of choosing the locale that should be used to format the message before writing it to the log and so all clients have to view the message in the same language
  • The log file is larger than necessary as it has to hold the full formatted string rather than just the message ID and replacement strings
  • If you want to view the entries written to a remote log on that machine, it must have the .NET runtime installed and the EventLogMessages.dll file registered in the remote computer’s GAC.

Read on for the solution class at…. http://www.codeproject.com/csharp/eventlogex.asp

Thanks to the Author for this public code.

Testing SSL on Win Server 2003/IIS6

October 6, 2004

Hi there,

Been busy with lots of work with .NET Remoting Performance Testing and stuff.

Found something interesting so here goes.

There’s a nice easy way to test your IIS6 – SSL performance, install the free SelfSSL Certificate(SelfSSL Version 1.0) from the IIS Resource Kit (http://www.microsoft.com/downloads/details.aspx?FamilyID=56fc92ee-a71a-4c73-b628-ade629c89499&displaylang=en) . Its very easy to use (that’s what we look for right?) . Check out http://www.visualwin.com/SelfSSL/ for detailed directions on how to get your site into https (for testing only).

The following very useful (performance, analysis and deployment) tools are also available in the IIS6 Resource Kit package :

  • IISCertDeploy.vbs Version 1.0
  • Log Parser Version 2.1
  • Metabase Explorer Version 1.6
  • Permissions Verifier Version 1.0
  • Web Capacity Analysis Tool Version 5.2

Thanks to Microsoft and the authors of the http://www.visualwin.com/ site on which there is lots of other interesting info. on Win 2003 and IIS6.