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

Server.Transfer

When i use Server.Transfer to transfer a URL (IWillBeHeard.com) to a
directory within the Home Website (Different URL) it still references links
and images to IWillBeHeard.com/images/graphic.jpg instead of
images/grapic.jpg. The code i am using to transfer is below. I must be
missing something. I have tried this with a SubWeb and a simply directory
and get the same results both ways. The ideal way is using SubWebs.

Thank you in advance for your help.

<Script Runat="server">
dim strToString, strLocalPath, strPathAndQuery as string

Sub page_load(Sender as Object, E as EventArgs)
strToString = request.URL.tostring
strLocalPath = request.URL.LocalPath
strPathAndQuery = request.URL.PathAndQuery
strToString = replace(strToString, strPathAndQuery, "")
strToString = replace(strToString, "http://www.", "")
strToString = replace(strToString, "http://", "")

Select Case strToString
Case "youthgroupservices.com"
Server.Transfer("Home.htm")
Case "iwillbeheard.com"
Server.Transfer("IWillBeHeard/Default.htm")
End Select
End Sub
</script>
Feb 23 '06 #1
2 5573
I recommend you use Redirect from the Application_BeginRequest event
instead. If you do not want to show the new url to the user, then use
URL rewriting.

http://www.aspnetpro.com/NewsletterA...200309pj_l.asp

I also recommend you don't hardcode "http". What if it is accessed via
https? Instead use HttpContext.Current.Request.Url.Scheme. Below is a
method that I used in a similar situation. This is a directory
application, where the subweb was in a sub-folder of the main
application. I used an app setting to define the "authority" used to
access the sub-web. You may need to alter this slightly where I look
for and add 'PhoneDirectory' to the url path.

web.config (dev server):
<add key="Phone.HostAuthority" value="DevelopmentServerName:150/" />

web.config (prod server):
<add key="Phone.HostAuthority" value="www.MyWebDomain.com" />

don't forget to turn on tracing to see the trace statements appear on
the page (during testing):
<trace enabled="true" requestLimit="10" pageOutput="true"
traceMode="SortByTime" localOnly="true" />

global.asax.cs:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
string phoneAuthority =
ConfigurationSettings.AppSettings["Phone.HostAuthority"];

HttpRequest req = HttpContext.Current.Request;
TraceContext trace = HttpContext.Current.Trace;
if (trace.IsEnabled)
{
trace.Write("MyApp", "Calculating Path - used to determine what Url
variables are helpful");
trace.Write("MyApp", "ApplicationPath=" + req.ApplicationPath);
trace.Write("MyApp", "RawUrl=" + req.RawUrl);
trace.Write("MyApp", "AbsolutePath="+req.Url.AbsolutePath);
trace.Write("MyApp", "AbsoluteUri="+req.Url.AbsoluteUri);
trace.Write("MyApp", "Authority="+req.Url.Authority);
trace.Write("MyApp", "Fragment="+req.Url.Fragment);
trace.Write("MyApp", "Host="+req.Url.Host);
trace.Write("MyApp",
"HostNameType="+req.Url.HostNameType.ToString( ));
trace.Write("MyApp",
"IsDefaultPort="+req.Url.IsDefaultPort.ToString()) ;
trace.Write("MyApp", "Port="+req.Url.Port.ToString());
trace.Write("MyApp",
"AppSettings:Phone.HostAuthority="+phoneAuthority) ;
}
if (phoneAuthority == null || phoneAuthority.Length == 0)
return;
string requestAuthority = req.Url.Authority + req.ApplicationPath;
if (requestAuthority == phoneAuthority)
{ //authority matches, let's ensure 'PhoneDirectory' is part of path.
string appPath = req.ApplicationPath;
if (!appPath.EndsWith("/"))
appPath += "/";
string requestedPath =
req.Url.AbsolutePath.Substring(appPath.Length);
if (!requestedPath.ToLower().StartsWith("phonedirecto ry/"))
{
string newUrl = req.Url.Scheme + "://" + req.Url.Authority;
newUrl += appPath + "PhoneDirectory/" + requestedPath;
if (trace.IsEnabled)
trace.Write("MyApp", "Redirecting to:" + newUrl);
HttpContext.Current.Response.Redirect(newUrl);
}
else
{
if (trace.IsEnabled)
trace.Write("MyApp", "Url already includes '/PhoneDirectory/'");
}
}
else
{
if (trace.IsEnabled)
trace.Write("MyApp", "Phone.HostAuthority does not match current
request authority. No url action required.");
}
}

Feb 23 '06 #2
if you use server transfaer, the browser will not know the new url, but used
the request url to calc releative paths.

-- bruce (sqlwork.com)
"Mark Sandfox" <No****@NoSpam.com> wrote in message
news:38******************@newssvr14.news.prodigy.c om...
When i use Server.Transfer to transfer a URL (IWillBeHeard.com) to a
directory within the Home Website (Different URL) it still references
links and images to IWillBeHeard.com/images/graphic.jpg instead of
images/grapic.jpg. The code i am using to transfer is below. I must be
missing something. I have tried this with a SubWeb and a simply directory
and get the same results both ways. The ideal way is using SubWebs.

Thank you in advance for your help.

<Script Runat="server">
dim strToString, strLocalPath, strPathAndQuery as string

Sub page_load(Sender as Object, E as EventArgs)
strToString = request.URL.tostring
strLocalPath = request.URL.LocalPath
strPathAndQuery = request.URL.PathAndQuery
strToString = replace(strToString, strPathAndQuery, "")
strToString = replace(strToString, "http://www.", "")
strToString = replace(strToString, "http://", "")

Select Case strToString
Case "youthgroupservices.com"
Server.Transfer("Home.htm")
Case "iwillbeheard.com"
Server.Transfer("IWillBeHeard/Default.htm")
End Select
End Sub
</script>

Feb 23 '06 #3

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

Similar topics

6
by: StephenMcC | last post by:
Hi All, Got a quick query in relation to the Server.Transfer method available in IIS 5+/ASP. I've got an issue where I want to take a portion of an online app and extract this out into a web...
4
by: Harsh Thakur | last post by:
Hi, I'd like to know the performance related differences between Response.Redirect and Server.Transfer. I'd like to redirect the user to a different page. I can either do a...
5
by: Julien C. | last post by:
Hi all, I have an "EditeItem.aspx" page which lets me edit properties of an "Item". In the OnClick() event of my Save button, I do save Item changes to the database and then I redirect the user...
9
by: Mark | last post by:
Hello I'm trying to use a Server.Transfer in a try-catch (I cannot put it outside the Try-Catch as it is nested deep within a component that is called in a try-catch loop) The problem is that the...
5
by: Guadala Harry | last post by:
I've been reading up on Server.Transfer as well as doing some testing, and it appears to always raise the ThreadAbortException error. On one hand I've read a bunch of promotional-type material...
11
by: Alexander Bosch | last post by:
Hi, I'm having a problem similar to the one that's stated in this KB http://support.microsoft.com/default.aspx?scid=kb;en-us;839521 When I'm posting a page to itself with the bool value as true it...
8
by: bryan | last post by:
I've got a custom HttpHandler to process all requests for a given extension. It gets invoked OK, but if I try to do a Server.Transfer I get an HttpException. A Response.Redirect works, but I really...
6
by: n# | last post by:
A Basic Question in ASP.NEt 1.1 In Page_Load Event I am doing a Server.Transfer. But it throws an error on the browser windows showing "Server Application Not Found" Pls help me
4
by: evantay | last post by:
I'm using ASP.NET 2.0 with VS.NET 2005. I'm trying to access properties from my master pages within a page that inherits from that master page (a child page). However the values are always null....
2
by: =?Utf-8?B?YWxiZXJ0b3Nvcmlh?= | last post by:
Hi, I'm using Threads, and when I try to do Server.Transfer, I recieved an error. (child object does not exist...) My Code: Dim t As New Thread(AddressOf Hilo) Private Sub Hilo()...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.