24 July, 2008

Asp.Net Worker Process Recycling

If a Web application contains code that causes problems, and you cannot easily rewrite the code, it might be useful to limit the extent of the problems by periodically recycling the worker process that services the application. You can accomplish this by using what is known as Worker Process Recycling. Worker process recycling is the replacing of the instance of the application in memory. IIS 6.0 can automatically recycle worker processes by restarting the worker process, or worker processes, that are assigned to an application pool. This helps keep problematic applications running smoothly, and minimizes problems such as memory leaks. You can trigger the recycling of the worker processes assigned to an application pool by using worker process recycling methods that are based on elapsed time, the number of Hypertext Transfer Protocol (HTTP) requests, a set time of day, and two kinds of memory consumption, in addition to recycling on demand.

To configure all the above settings, go to the Properties window of the application pool in which your Web application is running using the IIS manager. Using the Recycling, Performance, and Health tabs in the Properties window, you can specify values for the above settings. Navigating to the Performance tab in the Properties dialog box of the DemoAppPool results in the following output.



When you set the recycling of worker processes using IIS manager, you also need to take the state management strategy of your ASP.NET application into consideration. Because every time the worker process is recycled, the ASP.NET state information will be lost rendering the application in an invalid state. One alternative to overcome this issue is to maintain state data external to the worker process, such as in a database. However, moving data to an external database to allow recycling can affect server performance in the following two ways:

  • Performance is reduced because of the added data management that is needed to move the data between the application and the database.
  • Recycling flushes any in-process data caches, so the caches need to be rebuilt.

If you have an application pool with applications that depend on state data, you must decide whether or not to recycle the worker processes that are assigned to that application pool. If you store state in the same process as that of IIS, and you don't want the state information to be lost, you must not recycle a worker process using the application pool configuration settings.

22 July, 2008

Encryption Sections of Web.config

Configuration files are just great ; they let you configure the website .It's a great place to store the information which you are going to be using throughout the application and which is not changing.

You can easily encrypt sections of web.config in ASP.NET 2.0. In the code below I have encrypted the ConnectionStrings section of web.config.

Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection configSection = config.GetSection("connectionStrings");

if (configSection.SectionInformation.IsProtected)
{
configSection.SectionInformation.UnprotectSection();
config.Save();
}
else
{
configSection.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
config.Save();
}

.NET Framework 2.0 introduces a protected configuration feature that you can use to encrypt sensitive configuration file data by using a command line tool. The following two protected configuration providers are provided although you can also implement custom providers.
  • RSAProtectedConfigurationProvider : This is the default provider and uses the RSA public key encryption to encrypt and decrypt data.
  • DPAPIProtectedConfigurationProvider : This provider uses the Windows Data Protection API (DPAPI) to encrypt and decrypt data.

You can also writing connection string dynamically:

Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
ConnectionStringsSection conSection = (ConnectionStringsSection)config.GetSection("connectionStrings");
conSection.ConnectionStrings["SQLConnectionString"].ConnectionString = "NewConnectionString";
config.Save();

[Please note that when you write to a web.config file the application restarts which means all the session and application variables are lost.]

08 July, 2008

New Features of VS-2008

Historically, Microsoft has introduced a new Visual Studio product to accompany a new Framework version, they did that with Framework versions 1.0 - 2.0 as follows:

>> Framework v 1.0 --- VS .NET 2002
>> Framework v 1.1 --- VS .NET 2003
>> Framework v 2.0 --- VS .NET 2005

Obviously, the 2.0 Framework represented major modifications to the coresoftware (new compilers a new CLR, etc) and so, of course there were bugs.There have since been service packs for both the 2.0 Framework and VS 2005 to address these issues.

Then, Microsoft did something a little different, they introduced some new.NET technologies, but instead of creating a *whole* new Framework with newcompilers, a new CLR, etc., they made a new Framework version that just hadwhat was necessary to run the new features (Windows CommunicationFoundation, Windows Workflow, Windows Presentation Foundation) and called that Framework version 3.0. Instead of making a new version of VisualStudio to do along with that, Microsoft created a plethora of add-in's to VS2005 that would make it work with the new 3.0 stuff.

Now, the latest version of the Framework is 3.5 (adds additional support forLINQ and Ajax on top of WF, WPF, and WCF). For this new release (now thatmost of the bugs have been worked out, Microsoft has released Visual Studio2008, which works against the 3.5 Framework (there are no add-in's andservice packs for this - - yet).

Essentially, VS 2008 gives you access to all of the new Framework stuff AND is really VS 2005 with all the bugs worked out. It is considered a very stable product and has the advantage of making all the latest .NET technologies rolled up into it.

Following are the new features that Microsoft has introduced in the VS2008.
  • LINQ Support
  • Expression Blend Support
  • Windows Presentation Foundation
  • VS 2008 Multi-Targeting Support
  • Inbuilt AJAX support for ASP.NET
  • JavaScript Debugging Support
  • Nested Master Page Support
  • LINQ Intellisense and Javascript Intellisense support for silverlight applications
  • Intellisense Support
  • Intellisense Filtering
  • Intellisense Box display position
  • Organize Imports or Usings
  • Visual Studio 2008 Split View
  • HTML JavaScript warnings, not as errors
  • Debugging .NET Framework Library Source Code
  • In built Silverlight Library
  • Visual Studio LINQ Designer
  • Inbuilt C++ SDK
  • Microsoft Popfly Support

To get detail information about these features Chick Here