Forums

ASP

This topic is locked

ASP.NET redirect code

Posted 20 May 2004 18:07:42
1
has voted
20 May 2004 18:07:42 Jeralyn Merideth posted:
I have 1 webspace and 3 sites. I need a working code to redirect to the appropriate site. Here is a code I was given that doesn't seem to be working:

<script language="C#" runat="server">

void Page_Load(object sender, System.EventArgs e) {

string strUrl = Request.Url.ToString().ToLower();
string strDomain;

if (!IsPostBack) {

// get domain name for the switch
if (strUrl.StartsWith("")) strUrl = strUrl.Substring(7);
int x = strUrl.IndexOf('/');

if (x > 0) strDomain = strUrl.Substring(0,x);
else strDomain = strUrl;

// redirect based on the domain name
switch (strDomain) {

case "www.cidercreekhollow.com":
Response.Redirect("cch/",true);
break;

case "www.thebakerspantry.com":
Response.Redirect("tbp/",true);
break;

case "www.vectorworksds.com":
Response.Redirect("vwds/",true);
break;

default: Response.Redirect("cch/",true);
break;
}
}
}
</script>

I have made all the necessary folders but it's still not working. Is there something wrong with the code?

TIA,

Jeralyn

Replies

Replied 20 May 2004 19:55:26
20 May 2004 19:55:26 Rene Bandsma replied:
Why not use HTTP POST as VBScript. Something like this:

<%
host=lcase(request.servervariables("HTTP_HOST")
SELECT CASE host

CASE "www.domainname.com"
response.redirect "/site1/index.htm"

CASE ELSE
response.redirect "/site2/select.htm"
END SELECT
%>
Replied 20 May 2004 22:45:54
20 May 2004 22:45:54 Jeralyn Merideth replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
Why not use HTTP POST as VBScript. Something like this:

&lt;%
host=lcase(request.servervariables("HTTP_HOST")
SELECT CASE host

CASE "www.domainname.com"
response.redirect "/site1/index.htm"

CASE ELSE
response.redirect "/site2/select.htm"
END SELECT
%&gt;
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Would it work with the .NET framework?

Jeralyn
Replied 23 May 2004 17:03:27
23 May 2004 17:03:27 Rene Bandsma replied:
Sure, why not. You can use Classic ASP within .NET.

I think that you are using just one file to redirect? I think serverside coding is better than clientside (javascript) coding. Therefore I use always vbscript as solution
Replied 23 May 2004 17:47:51
23 May 2004 17:47:51 Jeralyn Merideth replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
Sure, why not. You can use Classic ASP within .NET.

I think that you are using just one file to redirect? I think serverside coding is better than clientside (javascript) coding. Therefore I use always vbscript as solution
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Okay, so where should this file go? In the default page on the server or in the index document itself?

Jeralyn
Replied 23 May 2004 17:50:16
23 May 2004 17:50:16 Jeralyn Merideth replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
Sure, why not. You can use Classic ASP within .NET.

I think that you are using just one file to redirect? I think serverside coding is better than clientside (javascript) coding. Therefore I use always vbscript as solution
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

One more question: Where you have "site1" "site2" am I supposed to put the name of my site or the subfolders they will be residing in? I'm really new at this stuff!

Thanks,

Jeralyn
Replied 24 May 2004 15:19:00
24 May 2004 15:19:00 Rene Bandsma replied:
When you look at my code and changed it to the following:

<pre id=code><font face=courier size=2 id=code>
&lt;%
host=lcase(request.servervariables("HTTP_HOST")
SELECT CASE host

CASE "www.domainname.com"
response.redirect "/site1/index.htm"

CASE "www.anotherdomainname.com"
response.redirect "/site2/index.htm"

CASE ELSE
response.redirect "/site2/select.htm"
END SELECT
%&gt;
</font id=code></pre id=code>

Then when a user typs in "www.domainname.com" the code above is being loaded in the index.asp (or default.asp) page and will redirect to /site1/index.htm, in the other case the user will redirect to /site2/index.htm.

In your root theire are the following files, subfolders:

- index.ASP (for above code, so needed for redirecting)
- SITE1 [DIR] (directory for site1)
- index.htm (the first page where INDEX.ASP is pointed to)
- SITE2 [DIR] (directory for site2)
- index.htm (the first page where INDEX.ASP is pointed to)

In your webbrowser the following address is displayed when CASE "www.domainname.com" is true: "www.domainname.com/site1/index.htm".

Good luch
Replied 07 Jun 2007 18:08:42
07 Jun 2007 18:08:42 Dennis Moran replied:
When you use this redirect does it carry the domainname.com.

In your webbrowser the following address is displayed when CASE "www.domainname.com" is true: "www.domainname.com/site1/index.htm".

In your webbrowser the following address is displayed when CASE "www.anotherdomainname.com" is true: "www.anotherdomainname.com/site2/index.htm".

Please let me know.
Replied 29 May 2008 05:55:15
29 May 2008 05:55:15 Gen Burton replied:
Hi,

I used the same code in my, i have multiple sites being redirected with specific ports.
ex. case "www.mydomain.com"
response.redirect "www.myseconddomain.com:8080"

im using another port for my webmail
My problem is the port will actually appear on the address bar. (ex. www.mydomain.com:8080)
Is there a way that when redirected, the port will not appear? or is there a script that when redirected, it jist shows domain names without the port?



Why not use HTTP POST as VBScript. Something like this:

&lt;%
host=lcase(request.servervariables("HTTP_HOST")
SELECT CASE host

CASE "www.domainname.com"
response.redirect "/site1/index.htm"

CASE ELSE
response.redirect "/site2/select.htm"
END SELECT
%&gt;


Would it work with the .NET framework?

Jeralyn


Reply to this topic