How to get the Web Site Identification information from inside the application

M

Mike

I am relatively new to Web development and I have a pretty simple
question. How do I get the web site identification information (from
IIS) inside my aspx.cs? Spacifically I want the web pages name and the
port number.

Thanks.
 
J

Juan T. Llibre

re:
Specifically I want the web pages name and the port number.

If it's just the web page name, get it with
Request.ServerVariables["SCRIPT_NAME"];

However, I suspect that you want the domain name.
Get that with Request.ServerVariables["SERVER_NAME"]

Get the port with :
Request.ServerVariables["SERVER_PORT"]

Here's a script which shows how to get all of them :

server.aspx :
-------------
<%@ Page Language="C#" %>
<html>
<head>
<title>Server IDs</title>
</head>
<script language = "C#" runat="server">
public void Page_Load(Object sender, EventArgs e){

string pagename = System.IO.Path.GetFileName(Request.ServerVariables["SCRIPT_NAME"]);
script.Text = pagename;

string httpport = System.IO.Path.GetFileName(Request.ServerVariables["SERVER_PORT"]);
port.Text = httpport;

string domain = System.IO.Path.GetFileName(Request.ServerVariables["SERVER_NAME"]);
domain_name.Text = domain;

}
</script>
<html>
<body>
<form id="Form1" runat="server">
<p>
<asp:Label id="script" runat="server" /></asp:label><br/>
<asp:Label id="port" runat="server" /></asp:label><br/>
<asp:Label id="domain_name" runat="server" /></asp:label><br/>
</form>
</body>
</html>
--------
 
M

Mike

Thank you for the information.

The one thing I can't find in any of those places (I tried all the
above mentioned items) is the web site description. I actually want
the desctiption field under Web site identification on the properties
page of the web site in IIS.

I want this so that if I make 2 identical web sites for 2 different web
pages I can name them different things and name my performance counters
accordingly. The port alone won't be enough though because it is not
displayed in the folder view of IIS.

I tried Request.ServerVariables["SCRIP­T_NAME"] and it gives me he
name of the script (asmx file)
I tried Request.ServerVariables["SERVE­R_NAME"] and it gives me
127.0.0.1
Request.ServerVariables["SERVE­R_PORT"] does give me the port though,
thanks for that one.

Is there an object I can use to get the Web site description for the
web site that is running?

Thanks, Mike
 
J

Juan T. Llibre

re:
I tried Request.ServerVariables["SCRIP­T_NAME"]
and it gives me the name of the script (asmx file)

That's what you requested ( "the web pages name" ).

re:
I tried Request.ServerVariables["SERVE­R_NAME"]
and it gives me 127.0.0.1

If you're running as localhost, of course it will give you that.
The domain name is only returned if a domain actually exists.

re:
I want this so that if I make 2 identical web sites for 2 different web
pages I can name them different things and name my performance
counters accordingly.
Is there an object I can use to get the Web site description for the
web site that is running?

You might be able to use Request.ServerVariables["APPL_MD_PATH"]

That will return something like :
/LM/W3SVC/1/Root/VirtualDirectory

You can use that to assign a performance counter for that website.





Thank you for the information.

The one thing I can't find in any of those places (I tried all the
above mentioned items) is the web site description. I actually want
the desctiption field under Web site identification on the properties
page of the web site in IIS.

I want this so that if I make 2 identical web sites for 2 different web
pages I can name them different things and name my performance counters
accordingly. The port alone won't be enough though because it is not
displayed in the folder view of IIS.

I tried Request.ServerVariables["SCRIP­T_NAME"] and it gives me he
name of the script (asmx file)
I tried Request.ServerVariables["SERVE­R_NAME"] and it gives me
127.0.0.1
Request.ServerVariables["SERVE­R_PORT"] does give me the port though,
thanks for that one.

Is there an object I can use to get the Web site description for the
web site that is running?

Thanks, Mike
 
M

Mike

That will definetly give me a unique name, I think we found that
INSTANCE_ID will as well, but I actually would like to have the exact
name in IIS, so the people that administer the websites can look at the
Instance property in perfmon or MOM and compare it directly to the IIS
list and know which web service it is whithout digging. The easier I
make there job the more of it they can do :).

I am hoping that that information is exposed to the website, but I
realize it simply may not be. If anyone knows difenitevly please let
me know.

Thanks, Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,436
Messages
2,571,696
Members
48,796
Latest member
Greg L.
Top