473,396 Members | 1,938 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,396 software developers and data experts.

How to determine IIS Application name from asp.net?

Title says it all.

Long version is that I have a win 2003 server box with 2 nics in it, 1.1.1.1
and 2.2.2.2, both hosting websites that reference the same code location.

"happywebsite.com" is hosted on 1.1.1.1 on a website object called "happy"
and "sadwebsite.com" is hosted on 2.2.2.2 on a website object called "sad".
The home directory for both website objects "happy" and "sad" is
"C:\Inetpub\wwwroot\website". From the user's perspective, there are 2
distinct, unrelated websites. From my perspective, there is 1 website to
code and maintain, with 2 different skins.

I do this because "happywebsite.com" and "sadwebsite.com" require identical
functionality and only appear different via skin; however, each requires its
own SSL certificate matching the respective url; so AFAIK, while they can
reference the same code, they must also be hosted on seperate website
objects in IIS in order to assign them their own SSL cert.

So in the code, if Request.URL.Host contains "happy" or "sad", I use the
corresponding skin and the website takes on the appropriate visual identity
(and some other changes such as the company name, etc.) depending upon which
url the user visited.

This all works great until the user reaches the code somehow omitting the
"happy" or "sad" urls (i.e., they type either IP directly, or some
antiquated DNS entry erroneously resolves "fubar.com" to 1.1.1.1 or
2.2.2.2). It's rare, but technically I cannot rely on Request.URL.Host to
know which website I'm supposed to be "posing" as 100% of the time.

I could probably hard-code IPs 1.1.1.1 and 2.2.2.2 into code as a "plan B"
decision maker in the event the Host is unrecognized, but I would rather be
able to ask IIS which application or website object I am running because the
"happy" website object is always going to use the happy skin irrespective of
host name or IP address and seems to be the ultimate definitive check.
Mar 23 '07 #1
2 1488
On Mar 23, 9:36 pm, "1388-2/HB" <1...@1.netwrote:
Title says it all.

Long version is that I have a win 2003 server box with 2 nics in it, 1.1.1.1
and 2.2.2.2, both hosting websites that reference the same code location.

"happywebsite.com" is hosted on 1.1.1.1 on a website object called "happy"
and "sadwebsite.com" is hosted on 2.2.2.2 on a website object called "sad".
The home directory for both website objects "happy" and "sad" is
"C:\Inetpub\wwwroot\website". From the user's perspective, there are 2
distinct, unrelated websites. From my perspective, there is 1 website to
code and maintain, with 2 different skins.

I do this because "happywebsite.com" and "sadwebsite.com" require identical
functionality and only appear different via skin; however, each requires its
own SSL certificate matching the respective url; so AFAIK, while they can
reference the same code, they must also be hosted on seperate website
objects in IIS in order to assign them their own SSL cert.

So in the code, if Request.URL.Host contains "happy" or "sad", I use the
corresponding skin and the website takes on the appropriate visual identity
(and some other changes such as the company name, etc.) depending upon which
url the user visited.

This all works great until the user reaches the code somehow omitting the
"happy" or "sad" urls (i.e., they type either IP directly, or some
antiquated DNS entry erroneously resolves "fubar.com" to 1.1.1.1 or
2.2.2.2). It's rare, but technically I cannot rely on Request.URL.Host to
know which website I'm supposed to be "posing" as 100% of the time.

I could probably hard-code IPs 1.1.1.1 and 2.2.2.2 into code as a "plan B"
decision maker in the event the Host is unrecognized, but I would rather be
able to ask IIS which application or website object I am running because the
"happy" website object is always going to use the happy skin irrespective of
host name or IP address and seems to be the ultimate definitive check.
Try to use the HostingEnvironment Class (System.Web.Hosting Namespace)
There are following properties

Sitename
ApplicationId

The Sitename property returns a starting point name of the site and
ApplicationId - something like /w3svc/1/root

Mar 23 '07 #2


"1388-2/HB" <1@1.netwrote in message
news:kT*****************@newssvr13.news.prodigy.ne t...
Title says it all.

Long version is that I have a win 2003 server box with 2 nics in it,
1.1.1.1 and 2.2.2.2, both hosting websites that reference the same code
location.

"happywebsite.com" is hosted on 1.1.1.1 on a website object called "happy"
and "sadwebsite.com" is hosted on 2.2.2.2 on a website object called
"sad". The home directory for both website objects "happy" and "sad" is
"C:\Inetpub\wwwroot\website". From the user's perspective, there are 2
distinct, unrelated websites. From my perspective, there is 1 website to
code and maintain, with 2 different skins.

I do this because "happywebsite.com" and "sadwebsite.com" require
identical functionality and only appear different via skin; however, each
requires its own SSL certificate matching the respective url; so AFAIK,
while they can reference the same code, they must also be hosted on
seperate website objects in IIS in order to assign them their own SSL
cert.

So in the code, if Request.URL.Host contains "happy" or "sad", I use the
corresponding skin and the website takes on the appropriate visual
identity (and some other changes such as the company name, etc.) depending
upon which url the user visited.

This all works great until the user reaches the code somehow omitting the
"happy" or "sad" urls (i.e., they type either IP directly, or some
antiquated DNS entry erroneously resolves "fubar.com" to 1.1.1.1 or
2.2.2.2). It's rare, but technically I cannot rely on Request.URL.Host to
know which website I'm supposed to be "posing" as 100% of the time.

I could probably hard-code IPs 1.1.1.1 and 2.2.2.2 into code as a "plan B"
decision maker in the event the Host is unrecognized, but I would rather
be able to ask IIS which application or website object I am running
because the "happy" website object is always going to use the happy skin
irrespective of host name or IP address and seems to be the ultimate
definitive check.
Try the following:

private string GetHostName(string Host)
{
UriHostNameType type = Request.Url.HostNameType;

if (type == UriHostNameType.IPv4 || type == UriHostNameType.IPv6) {
return System.Net.Dns.GetHostByAddress(Host).HostName;
} else {
return Host;
}
}

Pass in, as the parameter, Request.Url.Host.
Testing on my local machine, not remotely.

HTH,
Mythran
Mar 23 '07 #3

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

Similar topics

1
by: Harald Schneider | last post by:
Hi, is there a possibility how to determine a services executable file name (and path) from within the service itself ? I need to create multiple services of the same application. The app...
18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
18
by: Keith Brown | last post by:
I have an application that allows embedded storage of ANY chosen file in an OLE field. The file could have been dragged-and-dropped into the field or it might have been selected and imported...
0
by: arnottclose | last post by:
I need to open a Target db and determine if it is in a compiled state and if not to Compile it. The Application.iscompiled status is showing the value for the host mdb - not the Target (when in...
1
by: Dan | last post by:
All, I am working on an application that allows users to track various items for various clients. For example Client A may have an object Box where Client B has an object Canister. When a user...
4
by: Dave | last post by:
Greetings, I have a web application that will be hosted on our intranet. I would like to determine, via code the user's windows login name and domain in the following format: DOMAIN\loginname...
4
by: lcifers | last post by:
Is there a way, through VB.NET, to determine if the user has selected this option? I am writing an application that does some string functions to rename files, and the file names get chopped up if...
40
by: Jeff | last post by:
I have a system on a network and want to determine if anyone is currently connected to the back-end files. An interesting twist is that I have noticed that some users can be connected (have the...
7
by: Doru Roman | last post by:
Hi, What is the fastest way to evaluate manually the result in this case: int a, b, c; a = 255; b = 122; c = a & b; The only way I know is transforming each number into the binary value...
3
by: Merk | last post by:
How can I programmatically determine the from within that method. For example, consider the following code: private void DoSomething() { string s = ???; }
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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...
0
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...
0
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...
0
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,...

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.