搞不清楚这两个的区别,特地百度了一下。下面这篇挺好就转来了,谢谢原作者.
另外根据我的实验当创建项目时指定Web Site时,添加webform会默认在代码中使用CodeFile。而创建项目时指定Web Application时,添加webform会默认在代码中使用CodeBehind。而创建的项目是Web Site时使用vs发布网站,指定属性是使用单页程序集的话,页头的配置属性会被动态修改,去掉CodeFile属性,并制定程序集的友好名。例如会转换为为如下形式:
<%@ page language="C#" masterpagefile="~/MasterPage.master" autoeventwireup="true" inherits="_Default, App_Web_default.aspx.cdcab7d2" title="无标题页" %>
App_Web_default.aspx.cdcab7d2.dll为vs自动编译出来的程序集,放在bin目录下。
下面是文章原文:
今天同事在把一个Web项目从 Web Site 升级成 Web Application 应用后部署的时候,报错:
Server Error in '/' Application.
--------------------------------------------------------------------------------
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: The file '/index.aspx.cs' does not exist.
Source Error: 
Line 1:  <%@ Page Language="C#" AutoEventWireup="true" CodeFile ="index.aspx.cs" Inherits="Community.IndexHomePage.index" %>
Line 2: 
原因就是不知道为啥,采用系统升级工具,没有把这个Web Page 的 CodeFile 变成 CodeBehind 。
而且仅仅只是这一个页面没升级,其他页面都升级了。
再加上这两个属性都是 Code 开头的,一不留神,就会觉得一个属性。结果忙活了一回。
CodeFile 与 CodeBehind 在使用上是有很大区别的
先看 MSDN 上的说明:
CodeBehind 
指定包含与页关联的类的已编译文件的名称。该属性不能在运行时使用。
Specifies the name of the compiled file that contains the class associated with the control. This attribute is not used at run time.
CodeFile 
指定指向页引用的代码隐藏文件的路径。此属性与 Inherits 属性一起使用可以将代码隐藏源文件与网页相关联。此属性仅对编译的页有效。
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. 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 也部署出去,否则就会报编译时错误,找不到文件...

asp.net 关于CodeFile和CodeBehind相关推荐

  1. ASP.NET中CodeFile与CodeBehind的区别

     一.CodeBehind 1.使用方式 <%@ Page Language="C#" AutoEventWireup="true" Codebehi ...

  2. ASP.NET CodeFile VS CodeBehind

    在ASP.NET开发环境中, 新建Asp.net项目.新生成的Aspx文件中,会自动生成如下代码. <%@ Page Language="C#" AutoEventWireu ...

  3. [ASP.NET]ASP.NET中的Inherits、CodeFile、CodeBehind的区别详解及OWIN及IDENTITY

    篇一 : ASP.NET中的Inherits.CodeFile.CodeBehind的区别详解 Inherits.CodeFile.CodeBehind 在 ASP.NET 中使用代码隐藏方法来设计W ...

  4. Inherits、CodeFile、CodeBehind

    Inherits.CodeFile.CodeBehind 在 ASP.NET 中使用代码隐藏方法来设计Web 窗体,可使页代码能够更清晰地从 HTML 内容中分离到完全单独的文件中. 通常一个 @pa ...

  5. CodeFile 与 CodeBehind 的区别

    昨天部署公司网站时发现某些页面出现"找不到文件"错误. 后发现原来是CodeFile 与 CodeBehind 的问题. 以下是它们的区别:(原文:CodeFile 与 CodeB ...

  6. aspx文件中CodeFile与CodeBehind的区别

    在ASP.NET中Web编程时,aspx Web 窗体的@page 指令有三个属性(Inherits.CodeFile.CodeBehind),我们在添加aspx页面时,会默认在代码中使用CodeBe ...

  7. Inherits、CodeFile、CodeBehind的区别

    Inherits.CodeFile.CodeBehind 在 ASP.NET中使用代码隐藏方法来设计Web 窗体,可使页代码能够更清晰地从 HTML 内容中分离到完全单独的文件中. 通常一个 @pag ...

  8. Inherits、CodeFile、CodeBehind的意义

    在 ASP.NET 中使用代码隐藏方法来设计Web 窗体,可使页代码能够更清晰地从 HTML 内容中分离到完全单独的文件中. 通常一个 @page 指令如下: <%@ Page language ...

  9. inherits java_ASP.NET中的Inherits、CodeFile、CodeBehind的区别详解

    Inherits.CodeFile.CodeBehind 在 ASP.NET 中使用代码隐藏方法来设计Web 窗体,可使页代码能够更清晰地从 HTML 内容中分离到完全单独的文件中. 通常一个 @pa ...

最新文章

  1. java中showconfirmdialog_Java小游戏之连连看
  2. 从“小”培养AI安全意识:OpenAI开源最新强化学习训练工具,安全约束自由定制,开箱即用...
  3. IDT系列:(一)初探IDT,Interrupt Descriptor Table,中断描述符表
  4. App后台开发运维和架构实践学习总结(12)——基于token的多平台身份认证架构设计
  5. JAVA 垃圾收集监控
  6. Android高级开发面试题目,再也不用担心不能升职加薪了。
  7. OpenXml开发-向文档中添加样式
  8. 内核调试技巧-逆向寻踪,揭开 LACP 协议流程的神秘面纱
  9. 简单粗暴卸载Oracle RAC
  10. 快递单号查询国外公司编码汇总_快递鸟
  11. Python 爬虫 ~ Prison Oriented Programming。
  12. 创建包含法定节假日、工作日、周末的日历表(mysql、oracle通用)
  13. c语言 函数拟合,曲线拟合成Y=a*(X^b)+c*(X^d)函数 - 数学 - 小木虫 - 学术 科研 互动社区...
  14. (七)打印机驱动设置—认识打印机接口
  15. 集群服务器中定时任务多次执行的解决方案
  16. freesurfer运行完recon-all怎么快速查看有没有报错?——核心命令tail重定向
  17. 驱动程序获取微软数字签名的方法
  18. 苹果拟在爱尔兰建数据中心 当地居民抗议
  19. CryEngineV UI 制作
  20. OTG 线与普通 USB 数据线的区别

热门文章

  1. FormData使用方法详解
  2. spring cloud + eurka 优雅停机
  3. ToolBar的使用
  4. 统计字数的小程序(1)
  5. 有什么网上兼职适合大学生做?
  6. ZIGBEE技术 Zigbee Technology
  7. 【华为OD机试真题 Python】单词搜索 - 找到它游戏
  8. Spotify将后端服务迁移到GCE
  9. Java内存结构内存模型
  10. 萌萌哒意念猫耳创始人Tomonori Kagaya:物对人的体谅才是未来