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. python内置函数简单归纳

    做python小项目的时候发现熟练运用python内置函数,可以节省很多的时间,在这里整理一下,便于以后学习或者工作的时候查看.函数的参数可以在pycharm中ctrl+p查看. 1.abs(x):返 ...

  2. 19 Python之面向对象(成员)

    1. 成员 在类中你能写的所有内容都是类的成员 2. 变量 1. 实例变量: 由对象去访问的变量. class Person: def __init__(self, name, id, gender, ...

  3. 丑陋的 shell 来一遍

    学习使人进步,好记性不如烂笔头 在线正则 在线正则 ^(.)(.).*?\2\1$ 正式开始总结 cat 反过来读取文件 tac file.txt nl --> number line 如 ca ...

  4. 一头扎进 JAVA

    硅不可 吉米 JAVA 基础 -- 基础不牢,地动山摇 子类应该比 父类更为 开放 (public protected default private) 子类方法不能比父类抛出更高异常( 可以为父类方 ...

  5. 【转载】java工程师学习之路---给自己的目标

    想学习或者提升java的可以看看,单从java角度来看总结的虽然还是很全面的,主要是为了自己看 http://blog.csdn.net/peace1213/article/details/50849 ...

  6. scrapy-redis 实现分布式爬虫

    分布式爬虫 一 介绍 原来scrapy的Scheduler维护的是本机的任务队列(存放Request对象及其回调函数等信息)+本机的去重队列(存放访问过的url地址) 所以实现分布式爬取的关键就是,找 ...

  7. 让IE6、IE7、IE8、IE9、IE10、IE11支持Bootstrap的解决方法

    最近做一个Web网站,之前一直觉得bootstrap非常好,这次使用了bootstrap3,在chrome,firefox,safari,opera,360浏览器(极速模式).搜狗浏览器等浏览器下均没 ...

  8. python 出现OSError: [Errno 8] Exec format error的原因

    访问 .py文件的网页的时候会出现 Exec format error的问题, 一般情况下是由于基于Unix(Linux,Mac OS)系统下的问题,办法如下 1 .chmod +x  filenam ...

  9. 关于python3.8的一些新特性的解析与代码演示

    python3.8测试版出来了,我们来介绍一些变动,代码演示一下,当然底层相关的细节变动就不介绍了 只允许传位置参数 还记得如果我们想让某些参数只能以关键字参数的方式传递该怎么做吗? def foo1 ...

  10. Go语言标准库之fmt.Scan

    Go语言fmt.Scan使用指南 本文介绍了Go语言中fmt包中从标准输入获取数据的的Scan系列函数.从io.Reader中获取数据的Fscan系列函数以及从字符串中获取数据的Sscan系列函数的用 ...