关于CodeFile和CodeBehind
2016-01-04 14:54
155 查看
<%@ 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 也部署出去,否则就会报编译时错误,找不到文件...
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/guwenzhong/archive/2009/11/09/4790409.aspx
作者:于为源 出处: http://www.cnblogs.com/yuanyuan/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利
相关文章推荐
- ubuntn 12.04源
- 随笔 2016-1-4
- android 4.4打开MTP模式以及USB CD Rom模式打开方法
- Oracle的rollup、cube、grouping sets函数
- swing 之FlowLayout 实现自动换行和滚动条添加
- 浅析JVM及其调优(一)
- QT运行时加载UI文件
- IIS将应用程序池配置为在计划时间执行回收 (IIS 7)
- memset和wmemset微软官网解释
- linux 静态库、共享库
- MSSQL查询某个表在哪些存储过程中使用过
- app业务开发(服务端)的一般流程
- SAP DataServices企业定制培训
- Html5添加移动触摸设备的在线签名和涂鸦插件教程
- 数据库之存储过程
- iOS网络编程
- Tomcat下配置数据库连接池
- JAVA虚拟机之六:虚拟机性能监控和故障处理工具
- SAP Lumira连接数据库
- iOS中的round/ceil/floorf函数略解