更改的WebResource.axd的请求的URL [英] Change the requested url of WebResource.axd

查看:137
本文介绍了更改的WebResource.axd的请求的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Web应用程序(http://www.something.com/social/competition/)目前要求的WebResource.axd文件是这样的:

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

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

由于我们使用urlrewiting在NetScaler可为/社会文件夹中的所有请求转发到包含这个程序一个单独的服务器场中,/根路径将无法正确解析,因为它会被请求资源从something.com应用程序。

As we're using urlrewiting in a Netscaler to forward all requests for the "/social" folder onto a seperate server farm containing this app, the "/" root path won't resolve correctly as it will be requesting the resource from the something.com app.

因此​​,我需要更改请求脚本的URL请求要么它明确:

Therefore I need to change the url of the requested script to either request it explicitly:

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

或使用相对路径来请求吧:

or to request it using a relative path:

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

到目前为止,我已经看了覆盖渲染方法,使用控制适配器和其他各种东西,但还没有真正的任何地方作为尚未得到。请帮助。

So far I've looked at overriding the render method, using a control adapter and various other things but haven't really got anywhere as of yet. Help please.

推荐答案

对,所以它变成了广泛的研究之后,它是几乎不可能覆盖渲染处理这些文件。所以,唯一的选择是一个肮脏的,肮脏的,可怕的黑客!

Right, so it turns out after extensive research that it's practically impossible to override the rendering process for these files. So the only other option was a filthy, dirty, horrible 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);

    }

这截取数据流的网页,并取代/WebResource.axd与WebResource.axd的的所有事件。因为它是一个相对路径它解决一级棒!

This intercepts the stream to the page and replaces all occurrences of "/WebResource.axd" with "WebResource.axd". As it's a relative path it resolves beautifully!

另一种解决方案发生,我这就需要安装Web应用程序到模仿/社会的关键字重定向的虚拟目录。这将导致asp.net更新HttpRuntime.AppDomainAppVirtualPath包括在页面上引用了/社会,因此将正确解析。

Another solution occurred to me which required installing the web application to a virtual directory which mimicked the "/social" keyword redirect. This would cause asp.net to update the HttpRuntime.AppDomainAppVirtualPath to include the "/social" in the references on the page and would therefore resolve correctly.

大高呼呐喊!

这篇关于更改的WebResource.axd的请求的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆