Disable stop deny web.config inheritance

I find a good article about Configuration Inheritance below:

Each ASP.NET Web Application has its own configuration file called web.config file. 
In fact every directory in ASP.NET application can have one. Settings in each web.config file apply to the pages in the directory where its placed, and all the subdirectories of that directory.This is called 

Configuration Inheritance. 

So if you create an ASP.NET application and set its web.config file, add custom HttpHandlers, UrlRewriting module etc and try to create another ASP.NET Web Application in the subfolder, you can end up having problems because application in the subfolder will inherit all the settings from its parent  web.config.

So if you for example setup UrlRewriter module in your root web applications like this:

      <httpModules>

        <add name=”UrlRewriteModule” type=”UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter”/>

        <add name=”ScriptModule” type=”System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″/>

      </httpModules>

And in your child web application (in subfolder) you are not using UrlRewriteModule, then if you try to run the child Web Application in your browser, you will get error like this:

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 
Line 88: <httpModules>
Line 89:   <add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter"/>
Line 90:   <add name="ScriptModule" type="System.Web.Handlers.ScriptModule,
          System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
Line 91: </httpModules>

Luckily, there is a easy solution to this problem.

Source Error: 
What happens here is that because UrlRewriteModule is configured in the parent’s folder web.config file, this setting is inherited by the child application’s web.config file, and because of this ASP.NET is looking for the UrlRewriteModule DLL file in the BIN directory, and off course its not there.

First thing you can do is to remove the problematic HttpModule in your child application web.config file using the removecommand like this:

      <httpModules>

        <remove name=”UrlRewriteModule” />

      </httpModules>

This would remove the handler and your application would run fine.
Or you could use <clear/> command like this:

      <httpModules>

        <clear/>

      </httpModules>

This would clear all the HttpModules in your child application.

But what to do when there are many settings in your root web.config file that you don’t want to be propagated to your child applications?

Here is the solution:
With the <location> attribute with inheritInChildApplications set to false in your root web.config file you can restrict configuration inheritance. 
So, by wrapping a section of your web.config file in <location> attribute you can instruct ASP.NET not to inherit those settings to child applications/folders and their web.config files.

In fact  you can wrap the whole <system.web> section in one <location> attribute and disable configuration inheritance so none of the parent settings from <system.web> will be inherited to the child applications you create in subfolders.

Here is how to use this in practice:

  <location path=”.” inheritInChildApplications=”false”>

    <system.web>
    …

    </system.web>   
  </location>

NOTE: Do remember that if you do this, you need to manually insert all the settings you need in the <system.web> for your child applications because none of the settings from the root web.config will be propagated…

Source:
http://www.aspdotnetfaq.com/Faq/how-to-disable-web-config-inheritance-for-child-applications-in-subfolders-in-asp-net.aspx

Chain ?? operator

You can chain more than one nullable variable and if all null it return string.Empty

string value = valx ?? valy?? valz ?? string.Empty;

Nice isnt it ?

Two kind of Garbage Collector

when working on client machine you can use server type garbage collector.But it uses more memory.By default in server OS uses Server type garbage collector. You can configure  in your web config like

<configuration>
   <runtime>
      <gcServer enabled="true"/>
   </runtime>
</configuration>

The CLR has two different GCs: Workstation (mscorwks.dll) and Server (mscorsvr.dll). When running in Workstation mode, latency is more of a concern than space or efficiency. A server with multiple processors and clients connected over a network can afford some latency, but throughput is now a top priority. Rather than shoehorn both of these scenarios into a single GC scheme, Microsoft has included two garbage collectors that are tailored to each situation.

Server GC:

  • Multiprocessor (MP) Scalable, Parallel
  • One GC thread per CPU
  • Program paused during marking

Workstation GC:

  • Minimizes pauses by running concurrently during full collections

The server GC is designed for maximum throughput, and scales with very high performance. Memory fragmentation on servers is a much more severe problem than on workstations, making garbage collection an attractive proposition. In a uniprocessor scenario, both collectors work the same way: workstation mode, without concurrent collection. On an MP machine, the Workstation GC uses the second processor to run the collection concurrently, minimizing delays while diminishing throughput. The Server GC uses multiple heaps and collection threads to maximize throughput and scale better.

Source: MSDN

use alias for generics in c#2.0

Aliased generics:

using ASimpleName = Dictionary<string, Dictionary<string, List<string>>>;

It allows you to use ASimpleName, instead of Dictionary<string, Dictionary<string, List<string>>>.

Use it when you would use the same generic big long complex thing in a lot of places.

Nice extention methods for Enums

I find  very nice Extention for enums  and i want to share it.

[Flags]
public enum ErrorTypes : int {
    None = 0,
    MissingPassword = 1,
    MissingUsername = 2,
    PasswordIncorrect = 4
}
 
public static class EnumExtensions {
 
    public T Append<T>(this System.Enum type, T value) {
        return (T)(object)(((int)(object)type | (int)(object)value));
    }
 
    public static T Remove<T>(this System.Enum type, T value) {
        return (T)(object)(((int)(object)type & ~(int)(object)value));
    }
 
    public static bool Has<T>(this System.Enum type, T value) {
        return (((int)(object)type & (int)(object)value) == (int)(object)value);
    }
 
}
 
...
 
//used like the following...
 
ErrorTypes error = ErrorTypes.None;
error = error.Append(ErrorTypes.MissingUsername);
error = error.Append(ErrorTypes.MissingPassword);
error = error.Remove(ErrorTypes.MissingUsername);
 
//then you can check using other methods
if (error.Has(ErrorTypes.MissingUsername)) {
    ...
}

http://stackoverflow.com/questions/9033/hidden-features-of-c/407325#407325