惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
L
LangChain Blog
Jina AI
Jina AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
雷峰网
雷峰网
T
Tailwind CSS Blog
MongoDB | Blog
MongoDB | Blog
博客园 - 【当耐特】
博客园 - 聂微东
V
Visual Studio Blog
博客园_首页
Engineering at Meta
Engineering at Meta
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The Cloudflare Blog
人人都是产品经理
人人都是产品经理
Apple Machine Learning Research
Apple Machine Learning Research
阮一峰的网络日志
阮一峰的网络日志
Microsoft Security Blog
Microsoft Security Blog
GbyAI
GbyAI
F
Fortinet All Blogs
C
Check Point Blog
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - 王庆

crosstool-ng搭建交叉编译环境注意事项 多重继承及虚继承中对象内存的分布 编写和调试Android下JNI程序流程 eclipse xml文件中按alt+/没有提示信息 Android NDK 工具链的使用方法(Standalone Toolchain) 编译Android VNC Server 使用gdb和gdbserver调试Android C/C++程序 openssl在多平台和多语言之间进行RSA加解密注意事项 LINUX开发使用的3个远程工具 NDK 链接第三方静态库的方法 动态生成程序集和类型 关于线程池的一段代码 理解ParseChildren用法 捕获ASP.NET程序发生的异常 Synchronized vs SyncRoot Exception vs ApplicationException 【转】Hashtable,ListDictionary,HybridDictionary比较 Monitor用法 C#多线程之Thread
快速查找ASP.NET产生的临时文件
王庆 · 2008-07-25 · via 博客园 - 王庆

我们知道,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名称。