0

Web サイトを公開する場合、いくつかのプリコンパイル オプションがあります。この例では、それが .ascx ユーザー コントロールであり (ページの動作は似ています)、[プリコンパイル済みサイトを更新可能にする] がチェックされていないとします。これらはあなたが持っているオプションの一部です:

  1. プリコンパイルしない: ユーザー コントロールのコンテンツは .ascx ファイルに残り、必要に応じて一時的な ASP.NET フォルダーにコンパイルされます。
  2. プリコンパイル、マージなし: メイン DLL (projectName.dll) がわずかに異なり、.ascx が消え、ascx コンテンツがどこにも見つからない??
  3. プリコンパイル、単一アセンブリへのマージ: メイン DLL はわずかに異なり、.ascx コンテンツは新しい単一アセンブリにあり、.compiled ファイルが表示されます
  4. プリコンパイルし、ページとコントロールを単一のアセンブリにマージします: #3 とほとんど同じです。単一のアセンブリはわずかに小さくなります (おそらくトップレベルのアセンブリは含まれません) #3 のコードの一部が含まれています) #3 と同じですが、現在は.コンパイル済みファイル。

方法論: WinMerge を使用して、パブリッシュ出力を #1 と #2、次に #2 と #3 などと比較しました。また、1 つの ascx から一意の単語を選択し、Agent Ransack を使用してパブリッシュ出力を検索しました (インデックス化されたコンテンツだけでなく、すべてを検索します)。

質問: #2 では、ユーザー コントロールの HTML コンテンツはどこに行き着くのでしょうか? つまり、DLL 内の公開された ascx コンテンツや .compiled ファイルがないと、サイトはどのように機能するのでしょうか? #1 では、必要に応じて .ascx からコンテンツを取得しますが、#2 では利用できません。

編集:私が尋ねた直後にサイトが読み取り専用になり、ビルド出力が無効であることに気付きました。質問を更新して、より正確かつ徹底的にしました。

4

1 に答える 1

1

何らかの方法で、公開された bin フォルダー内の生成された .dll になります。

.aspx および .ascx ファイルは、%>aaa<% の間のすべての文字列が Literal("aaa") に変換され、コントロール ツリーの正しい場所に挿入されたコントロール オブジェクト ツリーを生成します。

Page (または選択した基本 Page クラス) および WebUserControl の子孫であるこれらのクラスは、常にコンパイルされますが、プリコンパイルされずに、一時的な asp.net フォルダーに存在します。プリコンパイルでは、プリコンパイル済みパッケージ内にすぐに配置されます。

たとえば、次の .ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<div class="customhtml">
    <asp:Label ID="Label1" runat="server" Text="<%#Page.Title %>"></asp:Label>
    <asp:Button ID="Button1" runat="server" Text="Button" />
</div>

結果は次のようになります (マージなしオプション): webusercontrol.ascx.#hash#.compiled

<?xml version="1.0" encoding="utf-8"?>
<preserve resultType="3" virtualPath="/WebSite1/WebUserControl.ascx" hash="fffffff7f6e43006" filehash="8f74adc78f7714d1" flags="110000" assembly="App_Web_aslslubn" type="ASP.webusercontrol_ascx">
    <filedeps>
        <filedep name="/WebSite1/WebUserControl.ascx" />
        <filedep name="/WebSite1/WebUserControl.ascx.cs" />
    </filedeps>
</preserve>

コンパイルされたアセンブリを見つけることができます - App_Web_#hash# とタイプ - ASP.webusercontrol_ascx

逆アセンブルすると、次のクラス宣言が表示されます。

using System;
using System.Diagnostics;
using System.Globalization;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ASP
{
  public class webusercontrol_ascx : WebUserControl
  {
    private static bool __initialized;

    [DebuggerNonUserCode]
    public webusercontrol_ascx()
    {
      this.AppRelativeVirtualPath = "~/WebUserControl.ascx";
      if (webusercontrol_ascx.__initialized)
        return;
      webusercontrol_ascx.__initialized = true;
    }

    [DebuggerNonUserCode]
    private Label __BuildControlLabel1()
    {
      Label label = new Label();
      this.Label1 = label;
      label.ApplyStyleSheetSkin(this.Page);
      label.ID = "Label1";
      label.DataBinding += new EventHandler(this.__DataBindingLabel1);
      return label;
    }

    public void __DataBindingLabel1(object sender, EventArgs e)
    {
      Label label = (Label) sender;
      Control bindingContainer = label.BindingContainer;
      label.Text = Convert.ToString(this.Page.Title, (IFormatProvider) CultureInfo.CurrentCulture);
    }

    [DebuggerNonUserCode]
    private Button __BuildControlButton1()
    {
      Button button = new Button();
      this.Button1 = button;
      button.ApplyStyleSheetSkin(this.Page);
      button.ID = "Button1";
      button.Text = "Button";
      return button;
    }

    [DebuggerNonUserCode]
    private void __BuildControlTree(webusercontrol_ascx __ctrl)
    {
      IParserAccessor parserAccessor = (IParserAccessor) __ctrl;
      parserAccessor.AddParsedSubObject((object) new LiteralControl("\r\n<div class=\"customhtml\">\r\n    "));
      Label label = this.__BuildControlLabel1();
      parserAccessor.AddParsedSubObject((object) label);
      parserAccessor.AddParsedSubObject((object) new LiteralControl("\r\n    "));
      Button button = this.__BuildControlButton1();
      parserAccessor.AddParsedSubObject((object) button);
      parserAccessor.AddParsedSubObject((object) new LiteralControl("\r\n</div>\r\n"));
    }

    [DebuggerNonUserCode]
    protected override void FrameworkInitialize()
    {
      base.FrameworkInitialize();
      this.__BuildControlTree(this);
    }
  }
}

特に、追加されている LiteralControl として HTML コードを見つけることができます

[DebuggerNonUserCode]
private void __BuildControlTree(webusercontrol_ascx __ctrl)
{
  IParserAccessor parserAccessor = (IParserAccessor) __ctrl;
  parserAccessor.AddParsedSubObject((object) new LiteralControl("\r\n<div class=\"customhtml\">\r\n    "));
  Label label = this.__BuildControlLabel1();
  parserAccessor.AddParsedSubObject((object) label);
  parserAccessor.AddParsedSubObject((object) new LiteralControl("\r\n    "));
  Button button = this.__BuildControlButton1();
  parserAccessor.AddParsedSubObject((object) button);
  parserAccessor.AddParsedSubObject((object) new LiteralControl("\r\n</div>\r\n"));
}
于 2014-06-21T01:28:35.983 に答える