473,385 Members | 1,311 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Find Base URL Of My Web App?

This seems like a really, really dumb question, but I can't seem to find
the simple answer that it seems to deserve.

My C#/ASP.net 2.0 app needs to email a URL link back to the site from a
web page. Sending the email is no problem, but generating this URL is
giving me an annoying issue in testing because of the difference in URLs
between the VS web server and IIS.

Specifically, the URL that I need to send when testing locally (VS
built-in web server) is http://localhost:4323/Safely-Sent/Validate.aspx.
However, in IIS, I need http://Safely-Sent.com/Validate.aspx.

So, I'd like to have a magic function that returns the correct 'base'
url (http://localhost:4323/Safely-Sent/ or http://Safely-Sent.com) for
my running instance as appropriate, onto which I can append my page
name. I looked at Request object properties, and at UriBuilder, but
nothing looked like what's needed.

Is there something trivial that I'm overlooking?

Thanks in advance!
May 18 '07 #1
3 4400
http://west-wind.com/weblog/posts/269.aspx


"Alan Cohen" <am***@cornell.no.junk.please.eduwrote in message news:uP**************@TK2MSFTNGP06.phx.gbl...
This seems like a really, really dumb question, but I can't seem to find the simple answer that it seems to deserve.

My C#/ASP.net 2.0 app needs to email a URL link back to the site from a web page. Sending the email is no problem, but generating
this URL is giving me an annoying issue in testing because of the difference in URLs between the VS web server and IIS.

Specifically, the URL that I need to send when testing locally (VS built-in web server) is
http://localhost:4323/Safely-Sent/Validate.aspx. However, in IIS, I need http://Safely-Sent.com/Validate.aspx.

So, I'd like to have a magic function that returns the correct 'base' url (http://localhost:4323/Safely-Sent/ or
http://Safely-Sent.com) for my running instance as appropriate, onto which I can append my page name. I looked at Request object
properties, and at UriBuilder, but nothing looked like what's needed.

Is there something trivial that I'm overlooking?

Thanks in advance!

May 18 '07 #2
Thanks!

I've actually temporarily solved my problem by setting the VS web
server's virtual path to '/' - but I'll read the post you linked to
hopefully find a better solution.

Jon Paal [MSMD] wrote:
http://west-wind.com/weblog/posts/269.aspx


"Alan Cohen" <am***@cornell.no.junk.please.eduwrote in message news:uP**************@TK2MSFTNGP06.phx.gbl...
>This seems like a really, really dumb question, but I can't seem to find the simple answer that it seems to deserve.

My C#/ASP.net 2.0 app needs to email a URL link back to the site from a web page. Sending the email is no problem, but generating
this URL is giving me an annoying issue in testing because of the difference in URLs between the VS web server and IIS.

Specifically, the URL that I need to send when testing locally (VS built-in web server) is
http://localhost:4323/Safely-Sent/Validate.aspx. However, in IIS, I need http://Safely-Sent.com/Validate.aspx.

So, I'd like to have a magic function that returns the correct 'base' url (http://localhost:4323/Safely-Sent/ or
http://Safely-Sent.com) for my running instance as appropriate, onto which I can append my page name. I looked at Request object
properties, and at UriBuilder, but nothing looked like what's needed.

Is there something trivial that I'm overlooking?

Thanks in advance!

May 18 '07 #3
You may want to look at the System.Web.VirtualPathUtility class
(http://msdn2.microsoft.com/en-us/lib...thutility.aspx)
This class is specifically designed for working with ASP.Net Virtual paths
(paths that begin with a tilde (~)). A Virtual path is an application
root-relative path. For example, if you have a project at
http://localhost/Safely-Sent, and you're developing for
http://Safely-Sent.com, your application root path will differ from the root
path on the live site. That is, if you have an image named "foo.gif" in your
app's images folder, the root-relative path to that image on your dev
machine will be "/Safely-Sent/images/foo.gif" but on the live server it will
be "/images/foo.gif." By using a Virtual path, the virtual path will be the
same on both machines, i.e. "~/images/foo.gif".

The VirtualPathUtility class has a number of static members for working with
Virtual Paths. There are 2 in particular that I find very useful:

VirtualPathUtility.ToAbsolute(path)
VirtualPathUtility.ToAppRelative(path)

The ToAbsolute method will take a virtual path ("~/.....", or a relative
path ("../.....") and convert it to an absolute path ("/.....") which begins
at the web root. In addition, if you pass an absolute path to it, it remains
unchanged.

The ToAppRelative method will take an absolute path "/....." or a relative
path "../.....") and convert it to a Virtual path ("~/....")

For example, my web application stores URLs in a database. While working on
the app, I don't want to put bad URLs into the database, and if the location
of the web changes, I don't want to have to change all of the URLs. So, when
I insert a URL into my database, I use the ToAppRelative method to put
virtual paths into the database. My app then uses the ToAbsolute method to
translate these back into absolute paths in the web site when they are
fetched from the database.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"Alan Cohen" <am***@cornell.no.junk.please.eduwrote in message
news:uP**************@TK2MSFTNGP06.phx.gbl...
This seems like a really, really dumb question, but I can't seem to find
the simple answer that it seems to deserve.

My C#/ASP.net 2.0 app needs to email a URL link back to the site from a
web page. Sending the email is no problem, but generating this URL is
giving me an annoying issue in testing because of the difference in URLs
between the VS web server and IIS.

Specifically, the URL that I need to send when testing locally (VS
built-in web server) is http://localhost:4323/Safely-Sent/Validate.aspx.
However, in IIS, I need http://Safely-Sent.com/Validate.aspx.

So, I'd like to have a magic function that returns the correct 'base' url
(http://localhost:4323/Safely-Sent/ or http://Safely-Sent.com) for my
running instance as appropriate, onto which I can append my page name. I
looked at Request object properties, and at UriBuilder, but nothing looked
like what's needed.

Is there something trivial that I'm overlooking?

Thanks in advance!

May 18 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bill Murray | last post by:
I am using VS.NET 2003 and trying to deploy a service program(c++) to a Windows 2000 Server system. I have also written a small DLL (USSsetup.dll) that is used to start/stop the service using a...
11
by: George Styles | last post by:
Hi, I have a base object, CBase, and 2 sub-objects CSub1 and CSub2. Given that I have a pointer to CBase, can I find out (easily in a portable way) if the object is CSub1 or CSub2. (or...
3
by: Massimiliano Alberti | last post by:
Can someone check this? If it's OK, you can use however you want... :-) It should search for an element in an array and, if it can't find it, return the next element. key is what you are...
5
by: Nathan Bullock | last post by:
Hi, I have a base class, say Base and there are two classes, say Class1 and Class2 which are derived from Base. Is there any way for me, say from a static method in Base, to get a list of all...
5
by: Mike Labosh | last post by:
In VB 6, the Form_QueryUnload event had an UnloadMode parameter that let me find out *why* a form is unloading, and then conditionally cancel the event. In VB.NET, the Closing event passes a...
1
by: skootr | last post by:
I have a Public Interface defined in a class module. I also have a form that implements that interface After building the solution, I added an Inherited Form (inherited from the above-mentioned...
6
by: roland.bali | last post by:
Hi, Here is the basic setup, my base class is Shoe which has a child class called Sandal. I would like to create objects by calling Sandal.Load. But without overloading Load in Sandal and...
7
by: mrstephengross | last post by:
Let's say I have a python file with a base class, and a few derived classes: class Base: pass class Derived1(Base): pass class Derived2(Base):
0
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?= | last post by:
Hi all, my problem is about services. I try comment you all steps for my issue: My development environment: Windows XP SP2
0
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?= | last post by:
Hi all, my problem is about services. I try comment you all steps for my issue: My development environment: Windows XP SP2
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.