.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

How to convert & transfer one Host-URL with query-string to another HostUrl with same QryStr?

Posted By: Pravin     Posted Date: December 14, 2011    Points:5   Category :C#
I need to transfer one url to another Url.
eg:
http://www.abc.com/123 [to] http://www.cba.com/123

This both Url should work for same page.
I tried the below code on page load event but its not work:
protected void Page_Load(object sender, EventArgs e)
{
string strURL = "www.nrwire.com";

if (strURL == Request.Url.Authority)
{
strURL = Request.Url.Authority.Replace("localhost:1458", "http://www.newsreleasewire.com/31911 ");
Response.Redirect(strURL);
}
if (Request.Url.Authority.ToLower() == "localhost:1458")
{
string strUrl;
strURL = Request.Url.Authority.Replace("www.nrwire.com", "www.newsreleasewire.com");
Server.Transfer("www.newsreleasewire.com");
}

}

Please anyone give suggestion for this above issue?

Responses
Author: Faizal             
Posted Date: December 15, 2011     Points: 20   

Hello Pravin,

It seems like you are transferring from localhost to the valid domain URL...Is this you want or you want to transfer from one valida domain to another valid domain? like this one in your example


http://www.abc.com/123 [to] http://www.cba.com/123

If you want to transfer from one valid URL to another valid URl try this code in page load event


protected void Page_Load(object sender, EventArgs e)
{
string fromURL = Request.ServerVariables["SERVER_NAME"];
string destURL = Request.RawUrl;

if (fromURL.IndexOf("abc.com") == 0)
{
Response.StatusCode = 301; // this is for search engine if you don't care about search engine or serp remove this line of code
if (destURL.ToLower() == "/default.aspx")
{
Response.RedirectLocation = "http://www.cba.com";
}
else
{
Response.RedirectLocation = "http://www.cba.com" + destURL;
}
}
}



Thanks
Faizal

Author: Pravin             
Posted Date: December 22, 2011     Points: 20   

Hi Faizal,
Ya i need to pass vaild domain only, thanks for your reply, your code gives me an good idea to implement my code,its very useful.

Thank You.

Regard
Pravin



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend