ASP.NET 2.0 and utility classes.

 I'm working these days with ASP.NET 2.0 (actually 1.2) for several reasons. As I already posted ASP.NET 2.0 don’t come with building option inside VS.NET. ASP.NET compiles ASPX files and code behind files while application called from the first time. So if you add utility class to the project no one will compile your utility class and you can't use it. Even if you use Page Inherits attribute to set Page base class to class inside your project, the page won't recognize your base class at runtime. The only way I found out to add classes is by creating class libraries and references them from ASP.NET project. By the way the current version doesn't support project reference from ASP.NET projects.

 

I hope I'm missing something, although I can't see what… And if I don’t miss something I hope MS will add ability to add classes into ASP.NET application. One might say that this attitude better since ASP.NET just handles pages and all other classes that hold logic and data must be outside ASP.NET project. But still there are cases that you want classes inside ASP.NET.

3 Comments

  • No you don't miss anything. I miss that article. thanks!!!



    I guess you cant read all MSDN article.



  • Create a directory called 'code' and put all of your code files in there.



    Look out for your namespaces. By default, in 1.2 not sure about what it will look like in the beta, your pages live in the ASP. namespace. So if you have a utility class like:



    SomeNamespace.SomeClass.DoSomething()



    and you try to call it from an aspDotNet page as



    SomeClass.DoSomething()



    it will fail. You will need to either add an import statement to the consuming page to import the namespace or change the namespace on the consuming page to match up to the utility code.



    Hope this helps,



    Paul D. Murphy

    Microsoft MVP, ASP.NET

  • /me thinks you should just hold your horses for the Whidbey beta. As instructed, I'm keeping my mouth shut about possible upcoming ASP.Net features in VS. ;)

Comments have been disabled for this content.