ASP.NET Path With Virtual Directory

I needed to include a url in a confirmation email from my asp.net app. I am not sure whether it will be deployed to a virtual directory or its own site. Just getting the Authority from the Request will yield no virtual directory, so here’s what i came up with:

const string action = "Login/Confirm";
var uri = new UriBuilder(HttpContext.Current.Request.Url);
uri.Path = VirtualPathUtility.ToAbsolute("~/"+action);
uri.Port = -1;//remove :80 (use default)

var url = uri.ToString() //http://localhost/myapp/login/confirm

There is probably a better way of doing this, but it works.


Posted 06-18-2010 8:36 AM by Michael Nichols
Filed under:

[Advertisement]

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)