473,385 Members | 1,326 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,385 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 5594
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.