1

I'm in the process of learning .net, and I need to get the URI of a specific webform.

The framework is asp.net 3.5

Example: I'm in AboutMe.aspx.cs and I need to find out what the URI of Contactme.aspx would be. Edit to clarify: I would give this method the path to Contactme.aspx --> "~/Contactme.aspx" and get "www.porcupine.com/Contactme.aspx"

The reason I'm trying to figure this out is that I want to render an email template page, that has specific variables per person, and then be able to copy the entire page into a string via WebClient().DownloadString() method. But this method requires the URI of the page to convert to string.

Does anyone know of a way to do this? Or of an ELEGANT alternative way to do this (i.e., without just writing out the entire page as the body of a message, etc.)?

Gabrinthei
  • 23
  • 6
  • So basically you want the opposite of what this does? http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx – itsme86 Aug 07 '13 at 17:47
  • Just wanting to get the current URL? Look at -- http://stackoverflow.com/questions/1034621/get-current-url-with-javascript – George Johnston Aug 07 '13 at 17:51
  • @itsme86 Yes and no, since you just provide the virtual path to that method; I need something where I can provide either the virtual or physical path and get the URI of where it would be (i.e. give it ~/pizza.aspx and get www.porcupine.com/pizza.aspx). – Gabrinthei Aug 07 '13 at 17:58
  • @GeorgeJohnston Not at all. I need to find the URI of any of my other pages, not the one I'm on. – Gabrinthei Aug 07 '13 at 17:59

1 Answers1

0

This should work for what you need:

string url = Request.Url.Scheme + System.Uri.SchemeDelimiter + Request.Url.Host + (Request.Url.IsDefaultPort ? "" : ":" + Request.Url.Port) +  ResolveUrl("~/ContactMe.aspx");

In my case it returns:

http://localhost:3165/WebSite88/ContactMe.aspx
Hanlet Escaño
  • 17,114
  • 8
  • 52
  • 75
  • 1
    Holy yeti tits! Thank you so much! I'm glad there was such a _simple_ way to get that, ha! But seriously, thank you! – Gabrinthei Aug 07 '13 at 18:23