Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is a good way to get the current directory even when using rewrite. </p> <p>I needed this to cache some resources in localStorage for an offline web app. With asp.net mvc, the page parameters are written as subdirecties under a page which causes the relative paths to change. Therefore, I needed the absolute path as a key for the resource in the localStorage.</p> <p>Anyway, here it is:</p> <pre><code> var applicationRoot = new System.Uri(Request.Url, Href("~")); var rawURl = Request.RawUrl; var rawUrlAbsolute = new System.Uri(serverRoot, rawURl); var relativeToCurrentPath = Href("SOMETHING_DOESNT_MATTER/../"); var clientPathAbsolute = new System.Uri(rawUrlAbsolute, relativeToCurrentPath); var clientPathAbsoulteStr = clientPathAbsolute.AbsoluteUri; </code></pre> <p>This took me many attempts to figure out. Here is an example using my website:</p> <h3>The path without rewriter</h3> <pre><code> // applicationRoot = http://www.toldpro.com/ // rawURl = /Apps/GreekBible/App/A/B/C // rawUrlAbsolute = http://www.toldpro.com/Apps/GreekBible/App/A/B/C // relativeToCurrentPath = ../../../ // clientPathAbsolute = http://www.toldpro.com/Apps/GreekBible/ // clientPathAbsoulteStr = http://www.toldpro.com/Apps/GreekBible/ </code></pre> <h3>The path rewriten to a subdomain</h3> <pre><code> // applicationRoot = http://greekbible.toldpro.com/Apps/GreekBible/ // rawURl = /App/A/B/C // rawUrlAbsolute = http://greekbible.toldpro.com/App/A/B/C // relativeToCurrentPath = ../../../Apps/GreekBible/ // clientPathAbsolute = http://greekbible.toldpro.com/Apps/GreekBible/ // clientPathAbsoulteStr = http://greekbible.toldpro.com/Apps/GreekBible/ </code></pre> <h3>The rewrite rule:</h3> <p>For more information about this, the following is the rewrite rule I used:</p> <pre><code>// Rewrite: // http://greekbible.toldpro.com/App/* (Client) // to // http://www.toldpro.com/Apps/GreekBible/App/* (Actual) &lt;rule name="Subdomain rewriter" stopProcessing="true"&gt; &lt;match url="App/(.*)" /&gt; &lt;conditions&gt; &lt;add input="{HTTP_HOST}" pattern="^www\.toldpro\.com$" negate="true" /&gt; &lt;add input="{HTTP_HOST}" pattern="^greekbible\.toldpro\.com$" /&gt; &lt;/conditions&gt; &lt;action type="Rewrite" url="/Apps/GreekBible{URL}" /&gt; &lt;/rule&gt; </code></pre>
 

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