简体   繁体   English

带有代码的新页中未找到ASP.NET页错误

[英]ASP.NET Page Not Found Error in New Page with Code Behind

I inherent a large ASP.NET web form application and try to add a new test.aspx page with code behind to a newly created folder - test. 我固有了一个大型ASP.NET Web表单应用程序,并尝试将一个新的带有代码的test.aspx页添加到一个新创建的文件夹-test中。

Test.aspx: Test.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %>

test.aspx.cs: test.aspx.cs:

using System;

public partial class Test: System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("This is a test");
    }
}

In my web.config file, I make the Test folder be accessible to anyone. 在我的web.config文件中,我可以使任何人都可以访问Test文件夹。

  <location path="Test">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>

When I access it in my development machine using https://localhost/Test/Test.aspx . 当我使用https://localhost/Test/Test.aspx在开发机器中访问它时。 It works fine. 工作正常。 But after I deployed to my server. 但是在我部署到服务器之后。 I got error 404 - page can not be found when I do https://myserver/Test/Test.aspx . 我执行https://myserver/Test/Test.aspx时出现错误404-找不到页面。

The server is Windows 2008 R2. 该服务器是Windows 2008 R2。 All other existing pages serve fine except for this new one. 除此新页面外,其他所有现有页面均可正常运行。

Put another new page Test1.aspx without code behind in the same Test folder. 将另一个没有代码的新页面Test1.aspx放在同一Test文件夹中。

<script language="c#" runat="server">
public void Page_Load(object sender, EventArgs e)
{
  Response.Write("hello, world!");
}
</script>

https://myserver/Test/Test1.aspx . https://myserver/Test/Test1.aspx It returns me "hello, World!". 它返回我“你好,世界!”。

Put any image file in the same folder is accessible also. 将任何图像文件放在同一文件夹中也可以访问。 https://myserver/Test/test.gif . https://myserver/Test/test.gif

What could be wrong for a simple new .aspx page with codebehind? 对于一个简单的带代码隐藏的新.aspx页,可能会出错吗? I do not see anything in Windows event log or IIS log. 我在Windows事件日志或IIS日志中看不到任何内容。 How to debug this problem? 如何调试这个问题?

Please help 请帮忙

Moved from comment. 从评论移到。

Replacing CodeFile with CodeBehind solves the problem. CodeBehind替换CodeFile可解决此问题。

Basically, we use CodeBehind if we need to compile in Visual Studio before deployment. 基本上,如果需要在部署之前在Visual Studio中进行编译,则可以使用CodeBehind

CodeFile and Code-Behind CodeFile和代码隐藏

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM