【问题标题】:ASPX can't seem to find my code behind files?ASPX 似乎无法在文件后面找到我的代码?
【发布时间】:2013-12-24 08:44:57
【问题描述】:

无论出于何种原因,我的 .aspx 只会在 Page 指令使用 CodeFile 而不是 CodeBehind 时识别背后的代码。此外,它会在运行时给出解析器错误。但我需要 CodeBehind 来发布网站。

  • Web 应用程序中的每个其他页面都使用 CodeBehind。
  • 我已尝试删除并重新创建文件,即使将其留空,仍然出现错误。
  • 我已尝试删除设计器文件并将 .aspx 转换为 Web 应用程序。
  • 页面指令引用(命名空间、类)正确。
  • 尝试删除 obj。
  • 尝试清理和重建。

我在这里没有选择。到目前为止,我在谷歌上搜索的所有内容都没有成功。为什么不能使用 CodeBehind?!

.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/App/Masters/Default.Master" AutoEventWireup="true" CodeBehind="BlogPost.aspx.cs" Inherits="WebApplication.App.Templates.BlogPost" %>

.aspx.cs

namespace WebApplication.App.Templates
{
    public partial class BlogPost : BaseTemplate
    {

【问题讨论】:

  • stackoverflow.com/questions/73022/codefile-vs-codebehind - 也许你使用了错误的属性?
  • @Tim CodeFile 有效,但在发布时无效。此外,所有其他页面都可以正常使用 CodeBehind。突然就这样了。
  • 我想说我以前看过这个 - 这是一个特定的页面,对吧?我想当它发生在我身上时,我进行了清理/重建并且它起作用了。您可能想尝试的其他方法是删除 IIS 临时 Internet 文件。您必须停止 IIS 并手动深入到目录。 (我在使用 Ektron CMS 时经常看到这种情况)

标签: c# asp.net


【解决方案1】:

也许您的.csproj 文件以某种方式损坏了?

检查项目文件中的文件条目是否如下所示:

<Compile Include="BlogPost.aspx.cs">
  <DependentUpon>BlogPost.aspx</DependentUpon>
  <SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="BlogPost.aspx.designer.cs">
  <DependentUpon>BlogPost.aspx</DependentUpon>
</Compile>

【讨论】:

  • 这看起来可能是它。我找不到他们。我应该手动添加它们还是有更好的方法?
  • @Ber53rker 我的建议是重新创建文件,它应该自动添加到.csproj 文件中。尽管您说“我已尝试删除并重新创建文件”,但我不确定。无论哪种方式,您都可以毫无顾虑地手动编辑 csproj 文件,只需确保先在 Visual Studio 中“全部保存”即可。
  • @Ber53rker 另外,请确保在重新创建文件时使用正确的模板。使用C# &gt; Web &gt; Web Form
  • 这行得通。还必须添加对.aspx 的引用。我很担心为什么这种情况还在发生。没有发现任何关于未自动添加到 .csproj 的内容的 Google 方面的信息。希望当我提交这不会给我的同事带来问题。
  • 看这里。 stackoverflow.com/questions/36202205/… 有时 .csproj 文件中的项目可能会乱序。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多