Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'll admit that like others I'm a little confused by the question but I'm thinking you may just want it as a kind of easy to use shortcut...</p> <p>If you want something in the global page that you can use to get the current page url more easily than typing <code>Request.Url.ToString().ToLower()</code> repeatedly then you could do something like this:</p> <pre><code>public class Global : System.Web.HttpApplication { public string currentUrl { get { return Request.Url.ToString().ToLower(); } } } </code></pre> <p>This has the advantage over session that it will always return the current page url and not just the most recent request. For example if you call a page (A) and that calls a graphic object through an aspx page (B) then you will only get one URL stored in session so you might get unexpected results when A is actually given B's url.</p> <p>If you do actually want a shortcut on every page then what I'd actually suggest doing is something more like:</p> <pre><code>public class MyPage : Page { public string CurrentUrl { get { return Request.Url.ToString().ToLower(); } } } </code></pre> <p>Then rather than your pages inheriting from the standard Page class you inherit them all from MyPage and you get CurrentUrl available in all pages without even having to reference an external entity.</p> <p>If this isn't what you want then you may like to step back and describe the original problem that you are trying to solve rather than the problems with your solution. It may be that you are trying to get something working that is a bad idea to begin with. :)</p>
 

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