By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 1,629 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

Server.Transfer

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.