asp.netweb-configapp-code

App_Code and web.config


Let's say I have a class (MyClass.cs) in App_Code (using a ASP.NET web site, not project). There's no namespace assigned to the class.

How can I get that class to be valid in the web site .aspx pages? WHAT do I need to put in the web.config file and WHERE do I need to put it?

Do I <add assembly tag or do I <add type ??

Since the assembly tag requires version, culture, and public key, I'm not sure what those values are at compile time.

Do I just add a type tag? Where do I put it in the web.config?

EDIT: Ok, I found part of my answer. I was getting the error because "http://localhost/MyFolder" was not set as an "application" in IIS. However, I have a BUNCH of folders, "http://localhost/MyFolder2, http://localhost/MyFolder3, etc...

New question: Is there any way to NOT have MyFolder be an application, and still make it run correctly? I've heard of a "codesubdirectories" tag, is that useful and where would I put it? Thanks.


Solution

  • Going by your edit, have you tried moving the App_Code folder to the root of the site?

    /App_Code
    /MyFolder
    /MyFolder2
    /MyFolder3
    

    That may address your issue.

    You could also take a look at Scott Guthrie's Tip/Trick:

    Creating Sub Web Projects using the VS 2005 Web Applications

    Although this does use the Web Application projects, rather than web sites.

    Looking at the CodeSubDirectories config element - you probably could use this - it would need to be defined in the root web.config I guess.

    Also, note that the <assembly> references only need to contain version, culture and public key details if the assemblies are strongly named (and so have those values).