DotNetNuke Response.End() Doesn’t End

screamOK.  This one is just plain annoying!

For some reason that I’ve yet to be able to track down, Response.End() seems to have no impact at all under DotNetNuke.

I tried various hacks.  Including the one you’ve probably seen already about executing Response.End() twice.  No good.

Execute Response.Close() and then Response.End() … infinite loop!

But I was able to come up with a solution that is reliable.

The specific issue I was trying to solve was that I wanted a Module to render an RSS feed.  Typically the way you’d do this is Response.Write() out the RSS feed information and then Response.End() so that no more information will render.  But something up the line in DNN seems to be trapping that so that the DNN page renders immediately after the RSS feed I rendered.  Aside from that rendering a lot more information than I had in mind, it also doesn’t work when you view the RSS feed in most browsers.

What I ended up doing to fix the problem is I created a Response Filter that strips off the extra information and returns just the RSS feed back to the client.

Here’s the basic code:

public class RssFilter : Stream
{
    readonly Stream m_responseStream;
    readonly StringBuilder m_html = new StringBuilder();

    public RssFilter(Stream inputStream)
    {
        m_responseStream = inputStream;
    }

    public override bool CanRead
    {
        get { return true; }
    }

    public override bool CanSeek
    {
        get { return true; }
    }

    public override bool CanWrite
    {
        get { return true; }
    }

    public override void Close()
    {
        string tempResponse = m_html.ToString();
        tempResponse = tempResponse.Substring(0,
            tempResponse.IndexOf("</rss>",
            System.StringComparison.Ordinal) + 6);

        byte[] data = Encoding.UTF8
            .GetBytes(tempResponse);
        m_responseStream.Write(data, 0, data.Length);
        m_responseStream.Close();
    }

    public override void Flush()
    {
        m_responseStream.Flush();
    }

    public override long Length
    {
        get { return 0; }
    }

    public override long Position { get; set; }

    public override long
        Seek(long offset, SeekOrigin direction)
    {
        return m_responseStream.Seek(offset, direction);
     }

    public override void
        SetLength(long length)
    {
        m_responseStream
            .SetLength(length);
    }

    public override int Read
        (byte[] buffer, int offset, int count)
    {
        return m_responseStream
           .Read(buffer, offset, count);
    }

    public override void
        Write(byte[] buffer, int offset, int count)
    {
        var sBuffer = Encoding.UTF8
            .GetString(buffer, offset, count);
        m_html.Append(sBuffer);

    }

}

 

Related Post

  • DotNetNuke Modules – Creating Base ModulesDotNetNuke Modules – Creating Base Modules Now that we have DotNetNuke installed into Visual Studio we can go ahead and create our first modules. Actually, creating the modules is pretty simple. But it is even easier to do it wrong, which...
  • DotNetNuke 5.x Can’t Move Module On A PageDotNetNuke 5.x Can’t Move Module On A Page As I mentioned a couple of days ago, the move to DotNetNuke 5 has brought about a few changes.  Some of them are design decisions that are just frustrating, like not being able to see that ...
  • DotNetNuke 5.14 Search User Enter Key IssueDotNetNuke 5.14 Search User Enter Key Issue I recently upgraded a DotNetNuke installation and found several issues that are either different from the 4.x series or are now broken. Most annoying is that there is now no longer any visual in...
  • Unrecognized Tag Prefix or Device Filter ‘asp’Unrecognized Tag Prefix or Device Filter ‘asp’ One of the companies I work for recently took over a project from another vendor.  As we started to maintain the site, we noticed that we could not drag and drop controls onto the page and ge...
  • DotNetNuke Modules – Creating the PADotNetNuke Modules – Creating the PA By now you have the basics for creating a DotNetNuke module.  The only question we have left to address is, how do we package this all up so that we can install it on another server? The file...
  • http://twitter.com/Richard_Myers/status/175645018894249984/ Richard Myers (@Richard_Myers)

    DotNetNuke Response.End() Doesn’t End http://t.co/4oI5gD1K