473,614 Members | 2,351 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Server.Transfer

When i use Server.Transfer to transfer a URL (IWillBeHeard.c om) to a
directory within the Home Website (Different URL) it still references links
and images to IWillBeHeard.co m/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(Sende r as Object, E as EventArgs)
strToString = request.URL.tos tring
strLocalPath = request.URL.Loc alPath
strPathAndQuery = request.URL.Pat hAndQuery
strToString = replace(strToSt ring, strPathAndQuery , "")
strToString = replace(strToSt ring, "http://www.", "")
strToString = replace(strToSt ring, "http://", "")

Select Case strToString
Case "youthgroupserv ices.com"
Server.Transfer ("Home.htm")
Case "iwillbeheard.c om"
Server.Transfer ("IWillBeHea rd/Default.htm")
End Select
End Sub
</script>
Feb 23 '06 #1
2 5700
I recommend you use Redirect from the Application_Beg inRequest 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.Cur rent.Request.Ur l.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.Host Authority" value="Developm entServerName:1 50/" />

web.config (prod server):
<add key="Phone.Host Authority" value="www.MyWe bDomain.com" />

don't forget to turn on tracing to see the trace statements appear on
the page (during testing):
<trace enabled="true" requestLimit="1 0" pageOutput="tru e"
traceMode="Sort ByTime" localOnly="true " />

global.asax.cs:
protected void Application_Beg inRequest(Objec t sender, EventArgs e)
{
string phoneAuthority =
ConfigurationSe ttings.AppSetti ngs["Phone.HostAuth ority"];

HttpRequest req = HttpContext.Cur rent.Request;
TraceContext trace = HttpContext.Cur rent.Trace;
if (trace.IsEnable d)
{
trace.Write("My App", "Calculatin g Path - used to determine what Url
variables are helpful");
trace.Write("My App", "ApplicationPat h=" + req.Application Path);
trace.Write("My App", "RawUrl=" + req.RawUrl);
trace.Write("My App", "AbsolutePath=" +req.Url.Absolu tePath);
trace.Write("My App", "AbsoluteUri="+ req.Url.Absolut eUri);
trace.Write("My App", "Authority="+re q.Url.Authority );
trace.Write("My App", "Fragment="+req .Url.Fragment);
trace.Write("My App", "Host="+req.Url .Host);
trace.Write("My App",
"HostNameType=" +req.Url.HostNa meType.ToString ());
trace.Write("My App",
"IsDefaultPort= "+req.Url.IsDef aultPort.ToStri ng());
trace.Write("My App", "Port="+req.Url .Port.ToString( ));
trace.Write("My App",
"AppSettings:Ph one.HostAuthori ty="+phoneAutho rity);
}
if (phoneAuthority == null || phoneAuthority. Length == 0)
return;
string requestAuthorit y = req.Url.Authori ty + req.Application Path;
if (requestAuthori ty == phoneAuthority)
{ //authority matches, let's ensure 'PhoneDirectory ' is part of path.
string appPath = req.Application Path;
if (!appPath.EndsW ith("/"))
appPath += "/";
string requestedPath =
req.Url.Absolut ePath.Substring (appPath.Length );
if (!requestedPath .ToLower().Star tsWith("phonedi rectory/"))
{
string newUrl = req.Url.Scheme + "://" + req.Url.Authori ty;
newUrl += appPath + "PhoneDirec tory/" + requestedPath;
if (trace.IsEnable d)
trace.Write("My App", "Redirectin g to:" + newUrl);
HttpContext.Cur rent.Response.R edirect(newUrl) ;
}
else
{
if (trace.IsEnable d)
trace.Write("My App", "Url already includes '/PhoneDirectory/'");
}
}
else
{
if (trace.IsEnable d)
trace.Write("My App", "Phone.HostAuth ority 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******** **********@news svr14.news.prod igy.com...
When i use Server.Transfer to transfer a URL (IWillBeHeard.c om) to a
directory within the Home Website (Different URL) it still references
links and images to IWillBeHeard.co m/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(Sende r as Object, E as EventArgs)
strToString = request.URL.tos tring
strLocalPath = request.URL.Loc alPath
strPathAndQuery = request.URL.Pat hAndQuery
strToString = replace(strToSt ring, strPathAndQuery , "")
strToString = replace(strToSt ring, "http://www.", "")
strToString = replace(strToSt ring, "http://", "")

Select Case strToString
Case "youthgroupserv ices.com"
Server.Transfer ("Home.htm")
Case "iwillbeheard.c om"
Server.Transfer ("IWillBeHea rd/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
2234
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 site on its own, so I will end up having two web sites. This planned to aid problems we've been having with performance, as if the portion (which is an app in its own right) has problems we then have to restart the whole site and so bring everything...
4
2103
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 Response.Redirect("URL") or a Server.Transfer("URL"). So I'd like to find out which is more efficient/better. Can anyone please tell me or give any pointers to links on the web? Thanks & Regards
5
7816
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 to the Item page "ViewItem.aspx" with a simple : Server.Transfer("ViewItem.aspx"); I'd like to pass another HTTP parameter so that in the "ViewItem.aspx" page,
9
4600
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 Server.Transfer always throws the ThreadAbortException. MSDN acknowledges that this is a unque exception that will be automatically rethrown - i.e. it can't be swallowed. Does anyone know if there is extar code I can write (maybe something in the...
5
2570
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 touting the benefits of Server.Transfer and none of them mention ThreadAbortException - but the MSDN documentation says Server.Transfer will always cause that exception - by design - and that the work-around is to not use Server.Transfer (and to use...
11
6019
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 falls into an infinite loop and later a StackOverflow Exception. I need to do this and not a Response.Redirect or a transfer with the bool in false. My problem is that this KB is saying that this problem should be solved with ServicePack 1 of...
8
3885
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 need to avoid the extra round-trip to the client. I've tried Passing the page name, the full URL, and the instance of the handler class to the Transfer method, but everything gets me the same error 500. Any help would be appreciated.
6
2180
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
3999
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. In my masterpage I have this: private bool m_AlreadyTested; public bool AlreadyTested { get { return m_AlreadyTested; }
2
3100
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() Thread.Sleep(1000)
0
8197
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8142
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8640
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8589
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8287
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7114
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5548
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4136
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2573
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.