Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript" src="../Scripts/jquery-1.2.6.js"></script>
- <script type="text/javascript" src="/Scripts/jquery-1.2.6.js"></script>
- <img src="~/Content/MyImage.jpg">
- <script type="text/javascript" src="<%=Url.Content("~/Scripts/jquery-1.2.6.js")%>"></script>
- <%=Html.ScriptInclude("~/Content/Script/jquery.1.2.6.js")%>
- <a href="@Url.Content("~/Home")">Application home page</a>
- <a href="~/Home">Application home page</a>
- <script src="<%=ResolveUrl("~/Scripts/jquery-1.2.6.min.js") %>" type="text/javascript"></script>
- using System;
- using System.IO;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Web;
- namespace Demo
- {
- public class PathRewriter : Stream
- {
- Stream filter;
- HttpContext context;
- object writeLock = new object();
- StringBuilder sb = new StringBuilder();
- Regex eofTag = new Regex("</html>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
- Regex rootTag = new Regex("/_AppRoot_", RegexOptions.IgnoreCase | RegexOptions.Compiled);
- public PathRewriter(Stream filter, HttpContext context)
- {
- this.filter = filter;
- this.context = context;
- }
- public override void Write(byte[] buffer, int offset, int count)
- {
- string temp;
- lock (writeLock)
- {
- temp = Encoding.UTF8.GetString(buffer, offset, count);
- sb.Append(temp);
- if (eofTag.IsMatch(temp))
- RewritePaths();
- }
- }
- public void RewritePaths()
- {
- byte[] buffer;
- string temp;
- string root;
- temp = sb.ToString();
- root = context.Request.ApplicationPath;
- if (root == "/") root = "";
- temp = rootTag.Replace(temp, root);
- buffer = Encoding.UTF8.GetBytes(temp);
- filter.Write(buffer, 0, buffer.Length);
- }
- public override bool CanRead
- {
- get { return true; }
- }
- public override bool CanSeek
- {
- get { return filter.CanSeek; }
- }
- public override bool CanWrite
- {
- get { return true; }
- }
- public override void Flush()
- {
- return;
- }
- public override long Length
- {
- get { return Encoding.UTF8.GetBytes(sb.ToString()).Length; }
- }
- public override long Position
- {
- get { return filter.Position; }
- set { filter.Position = value; }
- }
- public override int Read(byte[] buffer, int offset, int count)
- {
- return filter.Read(buffer, offset, count);
- }
- public override long Seek(long offset, SeekOrigin origin)
- {
- return filter.Seek(offset, origin);
- }
- public override void SetLength(long value)
- {
- throw new NotImplementedException();
- }
- }
- public class PathFilterModule : IHttpModule
- {
- public void Dispose()
- {
- return;
- }
- public void Init(HttpApplication context)
- {
- context.ReleaseRequestState += new EventHandler(context_ReleaseRequestState);
- }
- void context_ReleaseRequestState(object sender, EventArgs e)
- {
- HttpApplication app = sender as HttpApplication;
- if (app.Response.ContentType == "text/html")
- app.Response.Filter = new PathRewriter(app.Response.Filter, app.Context);
- }
- }
- }
- <a href="@Url.Content("~/Home")">Application home page</a>
- protected void Application_BeginRequest(object sender, EventArgs e)
- {
- Request.ServerVariables.Remove("IIS_WasUrlRewritten");
- }
- <script type="text/javascript" src="/MyProject/Scripts/jquery-1.2.6.js"></script>
- <a href=@Helper.Root()/about">About Us</a>
- public static string Root()
- {
- if (HttpContext.Current.Request.Url.Host == "localhost")
- {
- return "";
- }
- else
- {
- return "/productionroot";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement