views:

603

answers:

1

I have a website that has 2 files as follows:

  • page.aspx
  • page.aspx.cs

It used to be that I could just drop new files onto the web server and IIS would automatically compile the files and I could access the page e.g.

http://www.website.com/page.aspx

... and the associated functionality in the page class contained in the .cs file would work nicely.

Now I get the error: "Could not load type namespace.classname" which refers to my page class.

Now for some strange reason I have to put all my .cs files, even page classes into the app_code folder.

All that has changed on my website is that I reorganised the structure so that instead of my pages being on the web root they are now inside http://.../newfolder/page.aspx.

For some reason all my page.aspx.cs files now have to be in app_code.

Any ideas?

+2  A: 

Sounds like you are mixing up a Web Application Project and a Web Site.

Are you sure the files are exactly the same? Perhaps one @Page directive says CodeBehind=Page.aspx.cs and the other says CodeFile=Page.aspx.cs?

CodeBehind requires project compilation, so you cannot just drop in a new .cs file, you need to upload a new compiled DLL. CodeFile will allow dynamic compilation.

The App_Code directory is dynamically compiled (in both cases) when your app is accessed, so the Inherit directive has a valid type when you put the file there. In general, don't do this. You want the .cs file to go with the .aspx file. Use App_Code for business logic or utility classes that aren't associated with a particular page.

Finally, is this new subdirectory set up as a new app in IIS? What does the web.config file in your new directory change? Are you running the same version of ASP.NET? Check the "compilation" tag. I'm not sure what you could do there to cause this, but I'm sure you could cause some chaos.

Bryan