Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4090898
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:17:51+00:00 2026-05-20T19:17:51+00:00

I have just created an ASP.NET C# project and a virtual directory for it

  • 0

I have just created an ASP.NET C# project and a virtual directory for it in IIS in (as far as I know) the normal way, but I am seeing very strange behavior that I have never seen before.

It seems that none of my C# methods are ever being called. I know this because I have overridden a bunch of methods to do nothing but throw an exception. At least Default.aspx is viewable in the browser (see below)

Here is the exact content of my Default.aspx.cs file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Drawings2
{
    public partial class _Default : System.Web.UI.Page
    {
        static _Default()
        {
            throw new Exception("XXX");
        }
        public _Default()
        {
            throw new Exception("XXX");
        }
        override protected void OnInit(EventArgs e)
        {
            /*
             * base.OnInit(e);
             * InitializeComponent();
             */
            throw new Exception("XXX");
        }
        private void InitializeComponent()
        {
            /*
             * Load += new EventHandler(this.Page_Load);
             */
            throw new Exception("XXX");
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            throw new Exception("XXX");
        }
    }

}

I assume this code is not being loaded at all, because if it was then I would see an exception whenever I tried to view the page in the browser. Instead the content from the .aspx file appears normally (except that my event handlers are not called.)

It gets worse when I try to add new .aspx pages. I get this error when I try to view a new page in the browser (this is with the unmodified .cs file from the VS2008 template):
Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: Could not load type 'Drawings2.WebForm1'.

What can cause an ASP.NET site to get into this strange state?

Note: <%...%> escapes in the .aspx file still work fine. Also when I add form fields in the .aspx file, I can auto-complete their names in the .cs file. I have tried both true and false for AutoEventWireup on both pages. I have also tried adding and removing “partial” from all class declarations.


Update – here are my @Page tags. As I said, I have tried toggling AutoEventWireup. The referenced .cs files exist and compile with no errors.

<%@ Page Language="C#" AutoEventWireup="false" CodeBehind="Default.aspx.cs" Inherits="Drawings2._Default" %>

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Drawings2.WebForm1" %>

Related:

  • CodeFile vs CodeBehind
  • ASP.NET: Code behind or no code behind?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T19:17:52+00:00Added an answer on May 20, 2026 at 7:17 pm

    There’s a lot of conflicting information here. For example, if you are truly creating an ASP.NET Web Application (as opposed to a web site), then you should not be using CodeFile, as used2could suggests.

    Have you tried checking the Build Action of your code-behind files? Make sure it is set to Compile.

    I think we need to start you from scratch, to identify if the problem is coming from your web project, your IIS configuration, or both.

    I’m going to make the following assumptions about your set up, because this is my current set up. Let me know if any of these are wrong, but it shouldn’t make a huge difference:

    • You’re using Visual Studio 2010 with .NET 3.5
    • Your web server is Windows 2003
    • Your web server is running IIS 6.0

    Creating a new web app project:

    Let’s try to keep this as simple as possible, to minimize any chance of weirdness:

    • Solution ‘TestWebApp1’
      • Project ‘TestWebApp1’ (ASP.NET Web Application)
        • Properties
        • References
        • App_Data
        • Scripts
        • Default.aspx (Build Action: Content)
          • Default.aspx.cs (Build Action: Compile)
        • SiteLayout.Master (Build Action: Content)
          • SiteLayout.Master.cs (Build Action: Compile)
        • Web.config

    Contents of Default.aspx:

    <%@ Page Title="" Language="C#" MasterPageFile="~/SiteLayout.Master"
        AutoEventWireup="true" CodeBehind="Default.aspx.cs"
        Inherits="TestWebApp1.Default" %>
    <asp:Content ID="Content2" ContentPlaceHolderID="mainCPH" runat="server">
        <p><asp:Label ID="lblTest" runat="server">This is a test</asp:Label></p>
    </asp:Content>
    

    Contents of Default.aspx.cs:

    using System;
    namespace TestWebApp1
    {
        public partial class Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                lblTest.Text = "Modified from Default.aspx's Page_Load method.";
            }
        }
    }
    

    Contents of SiteLayout.Master:

    <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="SiteLayout.master.cs"
        Inherits="TestWebApp1.SiteLayout" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <body>
            <form id="form1" runat="server">
                <div>
                    <p><asp:Label ID="lblTest" runat="server">This is a test</asp:Label></p>
                    <asp:ContentPlaceHolder ID="mainCPH" runat="server">
                    </asp:ContentPlaceHolder>
                </div>
            </form>
        </body>
    </html>
    

    Contents of SiteLayout.Master.cs:

    using System;
    namespace TestWebApp1
    {
        public partial class SiteLayout : System.Web.UI.MasterPage
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                lblTest.Text = "Modified from master page's Page_Load method.";
            }
        }
    }
    

    Now, this site should work without fail when debugging in your local computer:

    site working locally

    Deploying to IIS

    1. Right click on TestWebApp1 project and click Publish.
    2. Choose File System as the ‘Publish method’ for simplicity.
    3. Enter a path where the files will be deployed.
    4. On your web server, open up IIS (I’m going to assume you’re running IIS 6.0)
    5. Under Default Web Site (or whatever site you use), create a new Virtual Directory. Make sure it has permissions to run Scripts.
    6. Copy the files that were published from your dev machine to the IIS virtual directory.
    7. That’s it — your site should be working fine.

    Basic VS 2010 Publish Dialog
    Virtual directory Access Permissions

    After following the above steps, are you still getting problems?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just starting out in asp.net. Have just created a login.aspx page in my site
I have just started playing with the ASP.Net MVC framework, and today I created
I'm trying to debug the MSBuild Customtask, that I have just created, but for
Have just started playing with ASP.NET MVC and have stumbled over the following situation.
If I have a datetime field, how do I get just records created later
I've just create a new MVC project, and have made no changes at all,
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have just inherited a server application, however it seems that the only copy
I have just installed C# for the first time, and at first glance it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.