Note that there are some explanatory texts on larger screens.

plurals
  1. POHttpModule breaks WebResource.axd
    primarykey
    data
    text
    <p>I wrote an HttpModule which does some simple content rewriting. It works fine, however it has a nasty side effect where the output of WebResource.axd is zero bytes. I've seen some references to this known issue online, but not with a filter quite like mine.</p> <p>Am I doing something (or neglecting to) here that would cause WebResource.axd to break? I'm using ASP.NET 4.0 on IIS 7.5.</p> <pre><code>Imports System.Text Imports System.Text.RegularExpressions Imports System.IO Imports System.Web Namespace HttpModules Public Class ResponseRewritingModule Implements IHttpModule Public Sub Init(ByVal app As HttpApplication) Implements IHttpModule.Init AddHandler app.ReleaseRequestState, AddressOf Me.OnReleaseRequestState End Sub Public Sub Dispose() Implements IHttpModule.Dispose End Sub Public Sub OnReleaseRequestState(ByVal s As Object, ByVal e As EventArgs) Dim app As HttpApplication = CType(s, HttpApplication) If (app.Request.Url.ToString().Contains(".aspx")) Then app.Response.Filter = New ImageUrlResponseFilter(app.Response.Filter) End If End Sub End Class Public Class ImageUrlResponseFilter Inherits MemoryStream Private responseStream As Stream Private matchpattern As String = "src=""/Images/" Private matchpattern2 As String = "url\(/Images" Private matchpattern3 As String = "src = ""/Images/" Private matchpattern4 As String = "src=""http://www.mydomain.com/Images/" Private replacementstring As String = "src=""http://images.mydomain.com/Images/" Private replacementstring2 As String = "url(http://images.mydomain.com/Images" Public Sub New(inputStream As Stream) responseStream = inputStream End Sub Public Overrides Sub Write(buffer As Byte(), offset As Integer, count As Integer) Dim strBuffer As String = System.Text.UTF8Encoding.UTF8.GetString(buffer) If (Not HttpContext.Current.Request.IsSecureConnection) Then strBuffer = Regex.Replace(strBuffer, matchpattern, replacementstring, RegexOptions.Compiled Or RegexOptions.IgnoreCase) strBuffer = Regex.Replace(strBuffer, matchpattern2, replacementstring2, RegexOptions.Compiled Or RegexOptions.IgnoreCase) strBuffer = Regex.Replace(strBuffer, matchpattern3, replacementstring, RegexOptions.Compiled Or RegexOptions.IgnoreCase) strBuffer = Regex.Replace(strBuffer, matchpattern4, replacementstring, RegexOptions.Compiled Or RegexOptions.IgnoreCase) responseStream.Write(UTF8Encoding.UTF8.GetBytes(strBuffer), offset, UTF8Encoding.UTF8.GetByteCount(strBuffer)) Else ' Do nothing for SSL connections responseStream.Write(buffer, offset, count) End If End Sub End Class End Namespace </code></pre> <p><strong>UPDATE:</strong> Daniel Richardson seems to have discovered the root cause and has a solution here: <a href="http://daniel-richardson.blogspot.com/2008/11/how-to-apply-filter-to-content-returned.html" rel="nofollow">http://daniel-richardson.blogspot.com/2008/11/how-to-apply-filter-to-content-returned.html</a></p> <p>Microsoft has apparently known about this issue for years and WILL NOT FIX IT: <a href="http://connect.microsoft.com/VisualStudio/feedback/details/105150/webresource-axd-output-always-truncated-when-used-with-a-response-filter" rel="nofollow">http://connect.microsoft.com/VisualStudio/feedback/details/105150/webresource-axd-output-always-truncated-when-used-with-a-response-filter</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload