Question

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">

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
Was it helpful?

Solution

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

OTHER TIPS

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

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top