I received that error:
Server Error in '/IndexPage' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
Source Error:
Line 17: {
Line 18: // Put user code to initialize the page here
Line 19: switch (Request.UrlReferrer.ToString())
Line 20: {
Line 21: case "http://domain.com/index.aspx":
Source File: e:\web sites\local host\indexpage\index.aspx.cs Line: 19
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
IndexPage.index.Page_Load(Object sender, EventArgs e) in e:\web
sites\local host\indexpage\index.aspx.cs:19
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET
Version:1.1.4322.2032
-------------------------------------------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace IndexPage
{
public class index : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
switch (Request.UrlReferrer.ToString())
{
case "http://domain.com/index.aspx":
Response.Redirect("http://forum.domain.com");
break;
case "http://www.domain.com/index.aspx":
Response.Redirect("http://forum.domain.com");
break;
case "http://www.domain2.com/SomePage.aspx":
Response.Redirect("page2.aspx");
break;
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Original Message ---
"Sathyaish" <sa*******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi,
Use the UrlReferrer property of the HttpRequest class. Say something
like this:
switch case(Request.UrlReferrer.ToString())
{
case "http://www.domain1.com/SomePage.aspx":
Response.Redirect("page1.aspx");
break;
case "http://www.domain2.com/SomePage.aspx":
Response.Redirect("page2.aspx");
break;
}
This code has some loop holes as in
"http://www.domain2.com/SomePage.aspx" might not be the exact string
returned by the UrlReferrer property, and you might have to use some
string handling like IndexOf() etc., but you get the basic idea, I
suppose.
Hope that helps.
Regards,
Sathyaish
Bishoy George wrote: Hi,
I want an asp.net code for redirection:
I have multiple domains pointing to one page , let's call it page0.aspx
I want to put a code in page0.aspx so
when domain1 opens page0.aspx it redirects it to page1.aspx
when domain2 opens page0.aspx it redirects it to page2.aspx
... etc
Is there a code for that?
Thank you.