English 中文(简体)
ASP.NET HttpModule, 采取应对措施时的奇怪行为。 A. 撰写本背景
原标题:ASP.NET HttpModule, strange behaviour when using Response.Write to the current context

我试图理解为什么这种非常简单的HttpModule失败。 该守则是我需要为测试项目开发的简明的HttpUrlRe author的前奏。

看来,每当我测试请求,然后执行答复时,产出就没有写给溪流!

I ve attached the debugger (VS 2008) to the module, and all 3 Response.Write statements in the below get executed, but only the two outer ones actually product output on the page. Have I missed a key understanding or caveat?

感谢任何帮助。

Exeucting Environment: ASP.NET 3.5/WinXP/IIS 5月

using System; using System.Collections.Generic; using System.Web; using System.Text; using System.Web.UI;

public class Interceptor : IHttpModule
{
    #region IHttpModule Members

    public void Dispose() { }

    public void Init(HttpApplication context)
    {
        context.EndRequest += new EventHandler(TestHandler);
    }

    private void TestHandler(object sender, EventArgs e)
    {
        HttpApplication app = (HttpApplication)sender;
        HttpContext ctx = app.Context;

        if (1 == 1)
        {
            ctx.Response.Write("Hello, 2"); // Works, as expected
        }

        string test = ctx.Request.Url.ToString();
        if (test.Contains("/images")) {
            ctx.Response.Write("Hello, never written"); // This code executes when the test passes, but nothing is ever written...
        }

        ctx.Response.Write("Hello"); // Works

    }

    #endregion
}
最佳回答

如果你要求图像,反应流也会不同!

问题回答

如果你正在监测此事,你肯定会打上打破僵局? 知道,如果你在这个/日志中有一个形象,并且有一页,显示你的模块将在发展服务器中两次被称作(用于 as和图像),而只是在违约的IIS(仅用于 as)。 当你同时要求使用该模块时,我们有时难以看到哪一个中断点是要求。

令人痛心的是,我的回答是顽固的。 那些被忽视的经典之一!

请求书虽然含有/age,但还是用于双亲档案。 因此,答复是为此而写到的,而不是原文。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签