在ASP.NET网站,在什么点codebehind是在文件的.cs编译? [英] In an ASP.NET website with a codebehind at what point are the .cs files compiled?

查看:170
本文介绍了在ASP.NET网站,在什么点codebehind是在文件的.cs编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在简介:
在ASP.net网站以code-后面,在什么点是*的.cs文件编译的?

In Brief: In an ASP.net website with a code-behind, at what point are the *.cs files compiled?

上下文:
谁曾从左边一位同事,部署了一个网站用的.cs code-后面共享服务器。我已经做了小改动一个cs文件,我应该会去反思的一个页面上,但还没有出现。我已经重新启动应用程序池,但我厌恶到服务器上重置IIS,因为有几个其他球队的应用程序可能会被使用。

Context: A colleague who has since left, deployed a website with a .cs code-behind to a shared server. I have made a small change to a .cs file, which I should expect to reflect on one of the pages but it has not yet appeared. I have restarted the application pool, however I am loathe to reset IIS on the server as there are couple of other teams apps which might be be in use.

推荐答案

这适用于 Web应用程序,而不是网​​站项目的项目,这是 codeFILE 默认情况下,并且不允许修改构建行动...

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...

在ASP.NET Web应用程序你有部署网页两种方法; codeFILE codeBehind 。默认情况下页面将始终使用 codeBehind ,但你可以改变这一点。

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您编译.cs文件到你的 bin中的.dll文件文件夹在编译/构建时,然后你部署到Web服务器。有没有必要部署cs文件到你的Web服务器。如果你这样做,它只是坐在那里不被使用。

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.

要配置带有codeBehind一个页面上,确保:

To configure a page with CodeBehind, ensure that:


  • 的.aspx 文件页面指令有 codeBehind =your.aspx.cs

  • 的.cs 了.Designer.cs 在Solution Explorer中的文件有一个<$ C $的性质建设行动>编译。

  • 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.

这会使ASP.NET编译服务器在cs文件上即时。这意味着你的的.cs 文件需要被部署到Web服务器。这也意味着,你的的.cs 文件将不会在编译编译/建造时间,因此不会内置到的.dll 文件夹中。

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.

使用codeFILE,您可以更改的.cs 文件和部署的只是文件,查看您的制作的变化网络服务器。无需重新部署。无需回收应用程序池。这可以在很多情况下是非常有用的。

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.

要配置带有codeFILE一个页面上,确保全部以下满足:

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


  • 的.aspx 文件页面指令有 codeFILE =your.aspx.cs

  • 在Solution Explorer中的的.cs 文件的属性有一个建设行动 内容

  • 在Solution Explorer中的了.Designer.cs 文件的属性有一个建设行动 <$ C的$ C>无。

  • 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.

  • IntelliSense不喜欢当页面设置与工作
    codeFILE(可以更改为codeBehind而编码,然后变回部署,虽然)。

  • 如果您从codeBehind更改为codeFILE,然后点击总是
    重建并重新部署(反之亦然)。这是因为当页面codeBehind,
    的.cs bin文件夹被编译成的.dll ,并会
    保留在那里,当你切换到codeFILE。在codeFILE会
    在编制上即时,你会得到同样的code /定义的类
    的.dll 的在上即时编译code,这将导致
    运行时错误。

  • 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 .dll in 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.

这篇关于在ASP.NET网站,在什么点codebehind是在文件的.cs编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆