HttpHandler uses default namespace

I have an HttpHandler called Handler, which I compile in a DLL and put in the / bin folder of my ASP.NET application. Then I have a .ashx file:

<% @ webhandler language="C#" class="Handler" %> 

but I get that I cannot create an error like Handler.

However, if I move the handler to a free namespace, say foo and change .ashx to

 <% @ webhandler language="C#" class="foo.Handler" %> 

It works great. Why can't I use the default namespace, er, namespace? Microsoft omits the namespace in many of the HttpHandlers examples on the msdn website.

+4
source share
1 answer

Thi is due to the nature of .Net Assemblies. Any reference type or ValueType should be wrapped around a namespace. Namespaces are used for logical grouping. In your case, your Handler class is a user-defined reference type. Any assembly can have one or many root namespaces in the root, but cannot have a reference type or value type in the root. In fact, when you create a class library project of a new class on the Applications tab in the project properties, it has the option "Define a default name" for your class library project. Therefore, whenever you create a new class in your project, it will wrap it around this DefaultSpace specified in ProjectProperties.Application.DefaultNameSpace.

If you want to see this in action, try opening your .Net assembly with IL Disassemblar, which comes with the .Net SDK.

+3
source

All Articles