473,805 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4419
http://west-wind.com/weblog/posts/269.aspx


"Alan Cohen" <am***@cornell. no.junk.please. eduwrote in message news:uP******** ******@TK2MSFTN GP06.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******** ******@TK2MSFTN GP06.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.Virt ualPathUtility 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 VirtualPathUtil ity class has a number of static members for working with
Virtual Paths. There are 2 in particular that I find very useful:

VirtualPathUtil ity.ToAbsolute( path)
VirtualPathUtil ity.ToAppRelati ve(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******** ******@TK2MSFTN GP06.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
7443
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 custom action. This dll is apparently dependent on the MSVCP71.DLL and MSVCR71.DLL's as per the Detected Dependencies folder visible in the deployment project All this good except I am UNABLE to Retarget the output of the msm merge...
11
1531
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 neither, but in my app its always 1 or the other) In Delphi, you would use the IS operation, eg
3
2230
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 searching, in a *base array of LONG with num elements. After some tests it seems to work well (the original version was filled with ASSERTs) (I will use this function in a bigger look-for-or-insert function) Some notes: The function returns the index...
5
2585
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 classes derived from Base? class abstract Base { static public ArrayList AllDerived()
5
3022
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 CancelEventArgs that lets me cancel the Close() operation, but is there still any way to find out *why* a form is closing? This app as a form that needs to be loaded at startup, closed only at shutdown, and then Show() / Hide() for the user. If...
1
2056
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 form) to the project via the IDE However, when I drop down the "(base class events)" list, I can't find the methods defined in the interface. I know the interface has been inherited because if I enter an "Implements" statement in the derived...
6
3625
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 sending the Sandal type to the base class I can not instantiate a Sandal class from within Shoe. Public Class Shoe Public Shared Function Load() As Object return ?????
7
1322
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
2880
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
6005
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
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10368
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10107
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.