IIS如何知道它是否提供一个Web站点或Web应用程序项目? [英] How does IIS know if it's serving a Web Site or a Web Application project?

查看:115
本文介绍了IIS如何知道它是否提供一个Web站点或Web应用程序项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,网站项目编译源即时和Web应用程序项目pre-源代码编译成DLL(很像ASP.Net 1.x中)。

但如何在IIS中指定的区别?

我知道的Visual Studio知道 - 有不同的项目对每个等,但正在运行的实例(IIS +框架)的的知道哪些编译模型正在被使用,对不对?因为怎么回事它知道是否要在编译最靠谱?

一个请求时,击中ASPX文件...以及如何做的过程中知道相关的CS文件是否需要编译(网站),或者如果它被部署(Web应用程序)之前就已经做了什么?

我只是好奇,其中规定这种差异。在web.config地方?


解决方案

有中,你会在这些项目类型中找到.aspx文件一个微妙的差异。

如果你看一个网站项目,你应该看到这样的事情...

 <%@页面语言=C#AutoEventWireup =真
codeFILE =Default.aspx.cs继承=_默认%GT;

...其中作为Web应用程序项目将有这样的事情.aspx文件...

 <%@页面语言=C#AutoEventWireup =真
codeBehind =Default.aspx.cs继承=WebApplication2._Default%GT;

注意,第一个具有codeFILE属性,第二个为codeBehind属性。这是区别制成。

在codeBehind属性不用于在运行 - 它的存在告诉VS.NET其中code生活,并继承属性告诉运行时去的二进制文件搜索的类。

的codeFILE属性用于在运行时,用于由aspnet_compiler.exe以产生code和然后In​​herits属性被用作上述

有关这些属性的更多信息,请看这里...

<一个href=\"http://msdn.microsoft.com/en-us/library/ydy4x04a.aspx\">http://msdn.microsoft.com/en-us/library/ydy4x04a.aspx

但是,为了回答你的问题如何IIS知道?答案是它没有。 ASP.NET知道了。

您可以证明,这是通过执行以下的情况:


  1. 创建一个新的Web应用程序。这将包括一个Default.aspx的和Default.aspx.cs。

  2. 添加以下code到Default.aspx.cs:

     保护无效的Page_Load(对象发件人,EventArgs的发送)
    {
        的Response.Write(你好);
    }


  3. 编译工程,运行它,看
    文本Hello出现在浏览器中。


  4. 现在,改变code,所以它看起来
    像这样的,并保存.cs文件:

     保护无效的Page_Load(对象发件人,EventArgs的发送)
    {
        的Response.Write(再见);
    }


  5. 不进行编译。刷新浏览器。您仍会看到你好,因为编译code仍然使用这个字符串。


  6. 现在,Default.aspx中的ATTRIB从codeBehind更改为codeFILE。保存该文件。


  7. 刷新浏览器。你会看到再见显示。


  8. 在code更改道别到我相信!。保存.aspx.cs但不进行编译。


  9. 刷新浏览器,看到了,在房间里enlightend舞蹈我相信!: - )


I understand that Web Site Projects compile source on-the-fly, and Web Application Projects pre-compile source into a DLL (much like ASP.Net 1.x).

But how is the difference specified in IIS?

I know that Visual Studio knows -- there are different projects for each, etc. But the running instance (IIS + Framework) has to know which compilation model is being used, right? Because how else does it know whether or not to compile on-the-fly?

A request comes in, hits an ASPX file...and how does the process know whether the associated CS file needs to be compiled (Web Site), or if it was already done before deployment (Web Application)?

I'm just curious where this difference is specified. In the web.config somewhere?

解决方案

There is a subtle difference in the .aspx file that you'll find in these project types.

If you look at a Web Site Project you should see something like this...

<%@ Page Language="C#" AutoEventWireup="true"  
CodeFile="Default.aspx.cs" Inherits="_Default" %>

... where as the Web Application project will have .aspx files with something like this...

<%@ Page Language="C#" AutoEventWireup="true" 
CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>

Notice that the first has a CodeFile attribute, and the second as a CodeBehind attribute. This is where the distinction is made.

The CodeBehind attribute is NOT used at runtime - it's there to tell VS.NET where the code lives, and the Inherits attribute tells the runtime which class to go searching for in the binaries.

The CodeFile attribute IS used at runtime, and is used by the aspnet_compiler.exe to generate code, and then the Inherits attribute is used as above.

For more info on these attributes, look here...

http://msdn.microsoft.com/en-us/library/ydy4x04a.aspx

But to answer your question "how does IIS know?" the answer is "it doesn't." ASP.NET knows.

You can prove that this is the case by doing the following:

  1. Create a new web application. This will include a Default.aspx and a Default.aspx.cs.
  2. Add the following code into Default.aspx.cs:

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("hello");
    }
    

  3. Compile the project, run it, see the text "hello" appear in a browser.

  4. Now, change the code so it looks like this, and save the .cs file:

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("goodbye");
    }
    

  5. DO NOT COMPILE. Refresh your browser. You'll still see "hello" because the compiled code still uses this string.

  6. Now, change the attrib in Default.aspx from CodeBehind to CodeFile. Save this file.

  7. Refresh your browser. You'll see "goodbye" displayed.

  8. Change "goodbye" in your code to "I believe!". Save the .aspx.cs but don't compile.

  9. Refresh your browser, see "I believe!", and dance around the room enlightend :-)

这篇关于IIS如何知道它是否提供一个Web站点或Web应用程序项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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