Click to See Complete Forum and Search --> : Request.ServerVariables


phpnstuff
03-05-2008, 06:35 PM
This is basic and works:

<% Response.Write("http://www.website.com" & Request.ServerVariables("URL")) %>

Is there a easier method to get the full url string in ASP.

I need 2 if statements, one if its https or http change the string, and the other is if only a few pages have query strings I want to do if query string exisits then add ? QueryString otherwise nothing (I don't want to have a "?" on every page http://www.website.com/default.asp? when there is no query, only if there is.

Rather than including this entire code everytime for every link I specify I want pulled, can we do a simple response.write(Function) ?

<%

Funtion =

%>

<% response.write(Function) %>

I'm new to ASP.

phpnstuff
03-06-2008, 10:30 AM
Anyhelp?

TheBearMay
03-06-2008, 11:16 AM
Not sure what you're really asking for, but see if this helps you (actually is Asp.NET):

<%@ Page Language = "c#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<%
String urlStr = "";
if (String.Compare(Request.ServerVariables["HTTPS"],"ON")==0) urlStr += "https://";
else urlStr += "http://";
urlStr +=Request.ServerVariables["SERVER_NAME"]+":"+Request.ServerVariables["SERVER_PORT"]+Request.ServerVariables["SCRIPT_NAME"];
if (String.Compare(Request.ServerVariables["QUERY_STRING"],"")!=0) urlStr += "?"+Request.ServerVariables["QUERY_STRING"];

Response.Write(urlStr);
%>
</body>
</html>