In an ASP.NET website with a codebehind at what point are the .cs files compiled?

This applies to Web Application projects as opposed to Web Site projects, which are CodeFile by default, and don't allow changing the build action...

In ASP.NET Web Applications you have two methods of deploying your pages; CodeFile and CodeBehind. By default pages will always use CodeBehind but you can change this.

CodeBehind

CodeBehind compiles your .cs file into the .dll file in your bin folder at compile/build time, and then you deploy that to your web server. There is no need to deploy the .cs file to your web server. If you do, it will just sit there being unused.

To configure a page with CodeBehind, ensure that:

  • The page directive in your .aspx file has CodeBehind="your.aspx.cs"
  • The properties of the .cs and .designer.cs files in solution explorer have a build-action of compile.

CodeFile

This causes ASP.NET to compile the .cs file on-the-fly on the server. This means that your .cs file needs to be deployed to the web server. It also means that your .cs file will not be compiled at compile/build time and therefore not built into your .dll in the bin folder.

Key advantage

With CodeFile, You can make changes to the .cs file and deploy just that file to see the changes on your production web server. No need to re-deploy. No need to recycle the app pool. This can be very useful in a lot of situations.

To configure a page with CodeFile, ensure that all of the following are met:

  • The page directive in your .aspx file has CodeFile="your.aspx.cs"
  • The properties of the .cs file in solution explorer have a build-action of content
  • The properties of the .designer.cs file in solution explorer have a build-action of none.

Notes

  • Intellisense doesn't like working when pages are set up with CodeFile (you can change to CodeBehind whilst coding and then change back for deployment, though).
  • If you change from CodeBehind to CodeFile, then always do a rebuild and re-deploy (and vice versa). This is because when the page was CodeBehind, the .cs was compiled into the .dllin the bin folder, and will remain there when you change to CodeFile. The CodeFile will be compiled on-the-fly and you will get the same code/classes defined in the .dll and in the on-the-fly compiled code, which will lead to runtime errors.

In an ASP.NET website with a codebehind at what point are the .cs files compiled?的更多相关文章

  1. ASP.NET 调试出现<%@ Application Codebehind="Global.asax.cs" Inherits="XXX.XXX.Global" Language="C#" %>

    ASP.NET 调试出现<%@ Application Codebehind="Global.asax.cs" Inherits="XXX.XXX.Global&q ...

  2. asp微信支付代码证书文件post_url.aspx和post_url.aspx.cs源码下载

    很多朋友在网上找的asp支付代码中都没有这两个证书文件,只能是用别人的,但是如果别人把他的网站这个文件删了,你的支付也就不能用了,今天我就把大家需要的这两个asp微信支付代码证书文件post_url. ...

  3. Fiddler捕捉ASP.NET WebSite调用WebService、WCF服务

    Fiddler默认会注册一个代理,有时会发现WebSite调用的WebService或者WCF服务无法被捕捉到.其实是由于运行的站点关联的应用程序池使用的账号和我们当前登陆操作系统的用户不同,自然它们 ...

  4. asp.net website 单独编译某个页面,连带编译app_code

    选中某一个页面,然后右键build page

  5. ASP.NET: Setup a MVC5 website with MySQL, Entity Framework 6 Code-First and VS2013

    The new features available in EF6 allow any developer to build a simple DB-powered website with very ...

  6. WebSite和WebApplication的区别

    1. WebApplication(Web应用程序)和WebSite(网站)的区别:WebSite是为了兼容从ASP转过来的开发人员的习惯而存在的,用起来简单,例如:不需要创建命名控件.C#代码修改以 ...

  7. WebApplication与WebSite区别

    1. WebApplication(Web应用程序)和WebSite(网站)的区别:WebSite是为了兼容从ASP转过来的开发人员的习惯而存在的,用起来简单,例如:不需要创建命名控件.C#代码修改以 ...

  8. 逐步改用 IronPython 开发你的 ASP.NET 应用程序

    IronPython for ASP.NET 的 CTP 已经发布有一段时间了,我们在看了官方提供的范例之后,相信对一个 ASP.NET 应用程序中完全使用 IronPython 开发还是有一些担心的 ...

  9. POCO Controller 你这么厉害,ASP.NET vNext 知道吗?

    写在前面 阅读目录: POCO 是什么? 为什么会有 POJO? POJO 的意义 POJO 与 PO.VO 的区别 POJO 的扩展 POCO VS DTO Controller 是什么? 关于 P ...

随机推荐

  1. Hadoop学习之 HIVE 多用户模式安装

    一.启动hadoop 集群 1.启动zookeeper 集群   zkServer.sh start 2.在master.hadoop 机器上 ./start-all.sh 由于 start-all命 ...

  2. javaScript基本使用api

    基本方法 isArray() 判断数组 isArray() 方法用于判断是否是数组(有兼容性) 语法:Array.isArray(arr) 返回值:是数组,返回true.不是数组,返回false. i ...

  3. 第一个简单的Echarts实例

    该示例使用 vue-cli 脚手架搭建 安装echarts依赖 npm install echarts -S 或者使用国内的淘宝镜像: 安装 npm install -g cnpm --registr ...

  4. leetcode297. 二叉树的序列化与反序列化

    代码 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * ...

  5. Linux排查磁盘空间顺序解决空间不足问题

    1 先查看整个磁盘的情况 df    -h                     查看整台服务器的硬盘使用情况 cd    /                       进入根目录 du   -s ...

  6. cmake编译c++程序

    当在Linux系统下编写程序时候,如果没有类似于visual studio.vs code等IDE(集成开发环境)时,如何编译.运行程序呢?一种方法是编写makefile文件,用makefile文件管 ...

  7. Android九宫格解锁有多少种姿势

    参考知乎:知乎.

  8. electron仿制qq(2) 主界面制作

    制作从头开始 最后会将写好的组件放到一起的!之前写了好几天的纯css 有点累 本章中将使用sass 如果代码太长 会分两个或多个章节写代码中会有详细的注释 以便于大家阅读and理解界面可能会有部分偏差 ...

  9. Mysql数据同步Elasticsearch方案总结

    Mysql数据同步Elasticsearch方案总结 https://my.oschina.net/u/4000872/blog/2252620

  10. Java基础——集合框架(待整理)

    ArrayList 和 和 Vector 的区别 从代码的最终的操作形式上可以发现,代码的输出结果与之前是一样的,而且没有区别,但是两者的区别还在于其内部的组成上. No. 区别点 Vector Ve ...