views:

785

answers:

3

I'm running in to a lot of inconsistencies with regards to what will compile and execute correctly in a Visual Web Developer 2008 Express environment and what fails on my web server.

In particular, I've got an aspx and aspx.cs codebehind, plus a number of additional .cs files in my Web Developer project. It builds fine and executes okay under the Development Server. Once I upload the files to my server, the codebehind doesn't seem to be aware of the other .cs files.

What's the correct way to make my aspx app inherit additional .cs files?

--- Update --- Since I'm not really finding the answer I need, let me be a little more explicit with what I'm doing:

I have three files:

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Import Namespace="UtilClasses" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

Default.aspx.cs

public partial class _Default : Page { }

App_Code/UtilClasses.cs

namespace UtilClasses {
  public class AClass {
    public const int A = 1;
  }
}

In this example, if I attempt to do any of the following, I'll get a compilation error on my web server:

  • Reference the App_Code with a @Import
  • Call the code contained in it from the aspx.cs codebehind or
  • Call the code from the aspx page.

It compiles fine in Web Developer 2008. The soltuion is a Web Site which is auto published to my web server via FTP. The exact list of files being published are:

  • Default.aspx
  • Default.aspx.cs
  • App_Code/UtilClasses.cs
  • web.config
+1  A: 

It seems like you have a deployment problem.

Just publish (in build menu there is a publish item) your web application/site to a folder and then move the files in that folder to your server.

I think you have old assembly files and new classes in your directory.

hope this helps

Canavar
Publishing isn't working correctly. Help me out. In the case of a project with a .aspx, a .aspx.cs, and a .cs, both of the *.cs files are not getting published. I'm choosing "Only files needed to run..."
Kivin
cs files are not published they are included ia your assembly files in bin directory. if you delete all files from your test server and copy all files in the publish directory it should work as you test in your developement environment. Your problem is a file conflict I think.
Canavar
Perhaps I need to change something in my @Page declaration then. When I clear the remote folder then republish, my page fails with a parser error: `The file '/test/testproj.aspx.cs' does not exist.`
Kivin
My issue was resolved with the webhosting company. That being said, this has become my preferred way to deploy an ASP.NET site.
Kivin
A: 

This is a very common problem of organizing code in your web applications. Here are some pointers to help you attend to your problem.

  1. If using a single project and it being ASP.net website project, put your .cs files in the app_code folder.

  2. Use namespaces wisely and keep track of what is in which namespace. If u have something like Resharper it saves this task.

  3. Ideally you should have only page related and util classes in your web project. Create libraries using C# express for other functions. Test these libraries using NUnit/MbUnit or the likes.

  4. If you have doubts if something runs on Cassini but not in IIS. A dev or local IIS is the only solution.

Hope that helps!

Perpetualcoder
I can't get the App_Code folder to work. Anything I put in there isn't visible to my application both in Web Developer and during runtime. I just get runtime errors "Such and such doesn't exist in the current context."
Kivin
You can't install add-ins like ReSharper to an instance of Web Developer, only in the full version of Visual Studio.
Zhaph - Ben Duguid
A: 

You can use partial classes. Add a file ( *.cs) and define your class as partial. So that, you can distribute your methods,properties anaother files

Sessiz Saat