CodeFile与Codebehind
今天拿VS2013在本机上往iis发布了一个网站,浏览网页的时候总是失败,提示找不到CodeFile,后来在网上搜索了一通,发现了问题的关键:
1 2 3 | <%@ Page Language="C#" AutoEventWireup="true" CodeFile="default.aspx.cs" Inherits="_Default" %> <%@ Page Language="C#" AutoEventWireup="true" Src="default.aspx.cs" Inherits="_Default" %> <%@ Page Language="C#" AutoEventWireup="true" Codebehind="default.aspx.cs" Inherits="_Default" %> |
--------------------------------------------------------------------------------------------------------------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | CodeBehind 指定包含与页关联的类的已编译文件的名称。该属性不能在运行时使用。 Specifies the name of the compiled file that contains the class associated with the control. This attribute is not used at run time. 指定包含与页关联的类的已编译文件的名称,编译完后所有cs中的代码打包进dll.该属性不能在运行时使用.提供此属性是为了与以前版本的 ASP.NET 的兼容,以实现代码隐藏功能。 CodeFile 指定指向页引用的代码隐藏文件的路径。此属性与 Inherits 属性一起使用可以将代码隐藏源文件与网页相关联。此属性仅对编译的页有效。比如VS2005中新建一个网站你会发现编译比WEB应用程序慢很多,但是可以修改代码后不用整体编译刷新页面就可以看到效果. Specifies a path to the referenced code-behind file for the control. This attribute is used together with the Inherits attribute to associate a code-behind source file with a user control. < br >The attribute is valid only for compiled controls. 我这里碰到的情况就是,整个Web 项目被编译成了组件,但是 ASPX 页面有如下的定义: <%@ Page CodeFile="***" Inherits="***" %> 这时候,ASP.net 就需要找 CodeFile 中指定的文件,以便动态编译,但是找不到,所以就报上述错误了。 对于开发时,即 页面的逻辑代码 cs 文件存在的时候,下属两种写法都没有问题。 <%@ Page Language="C#" AutoEventWireup="true" Codebehind="index.aspx.cs" Inherits="Community.IndexHomePage.index" %> <%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="Community.IndexHomePage.index" %> 但是部署到站点后,我们不会部署 cs 文件,这时候,后一种写法就会报找不到文件的错误了。除非你把 cs 也部署出去,否则就会报编译时错误,找不到文件... |
-----------------------------------------------------------------------------------------------------------------
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)