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

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.

原文地址:https://www.cnblogs.com/chucklu/p/11150449.html

时间: 2024-10-08 10:04:33

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

tutorial to create a multi-language ASP.NET website

http://www.codeproject.com/Tips/644196/Create-Multi-language-ASP-NET-Website http://www.hanselman.com/blog/GlobalizationInternationalizationAndLocalizationInASPNETMVC3JavaScriptAndJQueryPart1.aspx

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 few lines of code. There are many tutorials explaining how to do that with SQL Express available on the web, but those who want (or are forced) to us

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

IronPython for ASP.NET 的 CTP 已经发布有一段时间了,我们在看了官方提供的范例之后,相信对一个 ASP.NET 应用程序中完全使用 IronPython 开发还是有一些担心的.毕竟目前仅仅是 CTP 版本,并且缺乏 Visual Studio 的 Intellisence 的支持,在调试方面也有一些不足. 不过,今天我做了一些实验,发现可以在已有的 C# 的 ASP.NET 项目中引入 IronPython,而不会影响到原先程序的功能,这样,我们就可以混合使用 C#,

ASP.NET ASHX Handler

Some ASP.NET files are dynamic. They are generated with C# code or disk resources. These files do not require web forms. Instead, an ASHX generic handler is ideal. It can return an image from a query string, write XML, or any other data. Tutorial Fir

传智播客学习之ASP.net基础第七天

图片下载系统 需求:用户表增加一个级别字段.只有登录用户才能下载Images下的图片文件(Session中标识是否登录),如果用户没有登录则首先重定向到登录界面让用户登录,用户登录成功则跳转到下载列表页面,下载链接固定写好即可.如果登录用户是普通用户则在图片左上角加上“免费用户试用”的字样. 新建ImageDownload.aspx页面: <form id="form1" runat="server"> <div> <asp:Label

Professional C# 6 and .NET Core 1.0 - 40 ASP.NET Core

本文内容为转载,重新排版以供学习研究.如有侵权,请联系作者删除. 转载请注明本文出处:Professional C# 6 and .NET Core 1.0 - 40 ASP.NET Core ----------------------------------------------------------------------- What's In This Chapter? Understanding ASP.NET Core 1.0 and Web Technologies Using

ASP.NET MVC 入门1、简介

什么是MVC模式 MVC(Model-View-Controller,模型—视图—控制器模式)用于表示一种软件架构模式.它把软件系统分为三个基本部分:模型(Model),视图(View)和控制器(Controller). 那么MVC模式和我们熟悉的WebForm模式有什么不同呢?他的各个部分又是怎样分工的呢? 我们先来看一下普通的WebForm模式下,我们请求一个例如http://www.51mvc.com/blog/index.aspx的URL,那么我们的WebForm程序会到网站根目录下去寻

ASP.NET Routing

ASP.NET Routing Other Versions ASP.NET routing enables you to use URLs that do not have to map to specific files in a Web site. Because the URL does not have to map to a file, you can use URLs that are descriptive of the user's action and therefore a

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

写在前面 阅读目录: POCO 是什么? 为什么会有 POJO? POJO 的意义 POJO 与 PO.VO 的区别 POJO 的扩展 POCO VS DTO Controller 是什么? 关于 POCO Controller POCO Controller 应用 识别 POCO Controller 简单 POCO Controller IActionResultHelper IModelMetadataProvider.ViewDataDictionary IActionDiscovery