Changing namespace in ASP.NET Web-Form
When converting VS Web-Site to VS Web application One of the problem you might stumble upon is class name collisions. It is due to the fact that web-site, because of it’s compilation mode, can have the same class name (and no namespace) on different files because they will end up in different assemblies.
On web-application though, it is a different story. All classes ends up in the same assembly
and therefore we have to name them differently. You will encounter this problem when the compiler will say that '<YourPage>' already defines a member called 'Page_Load' or some other method /property/ field while you won’t see it anywhere else on the same file.
So, What do you need to do?
1. Add namespace to the code behind, do so for both aspx.cs and aspx.designer.cs files.
2. On the markup file (.aspx) page directive, change the “Inherits” attribute so it will corresponds to the new type name (<namespace>.<class>).
What not to do?
Do not use the option of overall changing the namespace. It will add namespace to all
classes by the same name and keep your name collisions in tact.
When converting some (not so) good old VS Web Site to VS Web Application you might encounter some class name collision. You can solve this collision by changing
namespaces however you should be very cautious while doing so.
Code snippet for session wrapped properties
Long ago, I’ve written about session manager class which provides type safety while
accession Session variables.
One of it’s foundations is the very properties we write that wraps the session variables.
These properties tends to be very much alike and therefore I’ve written a code snippet
It’s shortcut is propsess , you can copy it from below
<?xml version="1.0" encoding="utf-8" ?>
<Title>Session based Property</Title>
Code snippet for property with get and set accessors
that wraps a session variable
<ToolTip>Control Inner property</ToolTip>
/// Put summary for $name$
public $type$ $name$
return Session["$sessionKey$"] as $type$;
Session["$sessionKey$"] = value;