快速尋找ASP.NET產生的臨時檔案

來源:互聯網
上載者:User

我們知道,ASP.NET 頁面請求的處理過程需要使用一些臨時檔案,這些檔案對我們分析頁面程式邏輯,有很大的協助。下邊我就說兩種方法:

第一種,在頁面的Page_Load方法中加入

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write(this.GetType().Assembly.Location);
}

會輸出類似於下面的字串:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\website13\63ed8704\93b8f11b\App_Web_rixp4_rs.dll

我們去掉最後的App_Web_rixp4_rs.dll字元,將剩下的字串複製到“運行”視窗,開啟相應的檔案夾。

我們以default.aspx頁面為例,在開啟的檔案夾中找到類似於這樣的檔案default2.aspx.cdcab7d2.compiled。

我們開啟這個檔案,會看到類似於下面的內容:

<?xml version="1.0" encoding="utf-8"?>
<preserve resultType="3" virtualPath="/WebSite13/Default.aspx" hash="73ae13447" filehash="ffffe207cb3bfc04" flags="110000" assembly="App_Web_rixp4_rs" type="ASP.default_aspx">
    <filedeps>
        <filedep name="/WebSite13/Default.aspx" />
    </filedeps>
</preserve>

在開啟的檔案中,我們找到assembly="App_Web_rixp4_rs",在剛才開啟的檔案中找以App_Web_rixp4_rs開頭的類檔案。這些檔案就是我們需要的臨時檔案。

 

第二種,我們寫一個繼承IHttpHandlerFactory介面的檔案

public class HttpHandlerFactory : IHttpHandlerFactory
{
    public virtual IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
    {
        //得到編譯執行個體(通過反射)
        PageHandlerFactory factory = (PageHandlerFactory)Activator.CreateInstance(typeof(PageHandlerFactory), true);
        IHttpHandler handler = factory.GetHandler(context, requestType, url, pathTranslated);

        ResponseAssemblyLocation(context, handler);

        //返回
        return handler;
    }

    public virtual void ReleaseHandler(IHttpHandler handler)
    {
    }

    [Conditional("DEBUG")]
    private void ResponseAssemblyLocation(HttpContext context, IHttpHandler handler)
    {
        context.Response.Write(handler.GetType().Assembly.Location);
    }
}

然後在web.config進行配置一下:    <httpHandlers>
      <add verb="*" path="*.aspx" validate="false" type="HttpHandlerFactory"/>
    </httpHandlers>
        <compilation debug="true"/>

在debug="true"的情況下,類HttpHandlerFactory中的ResponseAssemblyLocation方法就能執行,反之,不執行。
需要說明的一點是,我產生的類檔案HttpHandlerFactory在網站的App_Code目錄,故web.config檔案中的type節未配置Assembly名稱。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.