Change the requested URL to WebResource.axd

My web application (http://www.something.com/social/competition/) is currently requesting the WebResource.axd file as follows:

<script src="/WebResource.axd?d=xxx" type="text/javascript"></script> 

Since we use urlrewiting in Netscaler to forward all requests for the / social folder to a separate server farm containing this application, the root path "/" will not be correctly resolved because it will request a resource from the something.com application.

Therefore, I need to change the url of the requested script so that it explicitly requests it:

 <script src="/social/WebResource.axd?d=xxx" type="text/javascript"></script> 

or query it using a relative path:

 <script src="WebResource.axd?d=xxx" type="text/javascript"></script> 

So far, I have been looking at overriding the rendering method using the control adapter and other other things, but have not received anything yet. Help me please.

+7
source share
1 answer

That's right, so after extensive research it turns out that it is almost impossible to override the rendering process for these files. So the only other option was a dirty, dirty, terrible hack!

 protected void Page_Load(object sender, EventArgs e) { //Initialises my dirty hack to remove the leading slash from all web reference files. Response.Filter = new WebResourceResponseFilter(Response.Filter); } public class WebResourceResponseFilter : Stream { private Stream baseStream; public WebResourceResponseFilter(Stream responseStream) { if (responseStream == null) throw new ArgumentNullException("ResponseStream"); baseStream = responseStream; } public override bool CanRead { get { return baseStream.CanRead; } } public override bool CanSeek { get { return baseStream.CanSeek; } } public override bool CanWrite { get { return baseStream.CanWrite; } } public override void Flush() { baseStream.Flush(); } public override long Length { get { return baseStream.Length; } } public override long Position { get { return baseStream.Position; } set { baseStream.Position = value; } } public override int Read(byte[] buffer, int offset, int count) { return baseStream.Read(buffer, offset, count); } public override long Seek(long offset, System.IO.SeekOrigin origin) { return baseStream.Seek(offset, origin); } public override void SetLength(long value) { baseStream.SetLength(value); } public override void Write(byte[] buffer, int offset, int count) { //Get text from response stream. string originalText = System.Text.Encoding.UTF8.GetString(buffer, offset, count); //Alter the text. originalText = originalText.Replace("/WebResource.axd", "WebResource.axd"); //Write the altered text to the response stream. buffer = System.Text.Encoding.UTF8.GetBytes(originalText); this.baseStream.Write(buffer, 0, buffer.Length); } 

This hooks the stream to the page and replaces all occurrences of "/WebResource.axd" with "WebResource.axd". Since this is a relative path, it decides perfectly!

I needed another solution that required installing the web application in a virtual directory that simulated the redirection of the / social keyword. This will cause asp.net to update HttpRuntime.AppDomainAppVirtualPath to include "/ social" in the links on the page and therefore fix it properly.

Big shout, scream!

+9
source

All Articles