ASP.NET clear source code

ApplicationPath class

using System;using System.Data;using System.Configuration;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;public class ApplicationPath : System.IO.Stream{    private System.IO.Stream baseStream;    public ApplicationPath(System.IO.Stream responseStream)    {        if (responseStream == null)        {            throw new ArgumentNullException("responseStream");        }        this.baseStream = responseStream;    }    public override bool CanRead    {        get { throw new NotImplementedException(); }    }    public override bool CanSeek    {        get { throw new NotImplementedException(); }    }    public override bool CanWrite    {        get { throw new NotImplementedException(); }    }    public override void Flush()    {        //throw new NotImplementedException();    }    public override long Length    {        get { throw new NotImplementedException(); }    }    public override long Position    {        get        {            throw new NotImplementedException();        }        set        {            throw new NotImplementedException();        }    }    public override int Read(byte[] buffer, int offset, int count)    {        return this.baseStream.Read(buffer, offset, count);    }    public override long Seek(long offset, System.IO.SeekOrigin origin)    {        throw new NotImplementedException();    }    public override void SetLength(long value)    {        throw new NotImplementedException();    }    public override void Write(byte[] buffer, int offset, int count)    {        string HTML = System.Text.Encoding.UTF8.GetString(buffer, offset, count);        HTML = HTML.Replace("src="/", "src="" + Classes.Common.ApplicationBaseUrl);        HTML = HTML.Replace("src='/", "src='" + Classes.Common.ApplicationBaseUrl);        HTML = HTML.Replace("href="/", "href="" + Classes.Common.ApplicationBaseUrl);        HTML = HTML.Replace("href='/", "href='" + Classes.Common.ApplicationBaseUrl);        HTML = HTML.Replace("action="/", "action="" + Classes.Common.ApplicationBaseUrl);        HTML = HTML.Replace("action='/", "action='" + Classes.Common.ApplicationBaseUrl);                buffer = System.Text.Encoding.UTF8.GetBytes(HTML);        this.baseStream.Write(buffer, 0, buffer.Length);    }}

Usage (ie from Master Page)

protected void Page_Load(object sender, EventArgs e){    //Response Filter to correct all application root paths to include proxy path    Response.Filter = new Classes.ApplicationPath(Response.Filter);}

Leave a Reply

Your email address will not be published. Required fields are marked *