Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried to remove the .aspx extension in the url bar for my web page but it is showing error my code is,

global.asax file:

C#
void Application_Start(object sender, EventArgs e)
       {
           RegisterRoutes(RouteTable.Routes);
       }

       private void RegisterRoutes(RouteCollection routeCollection)
       {
           routeCollection.MapPageRoute("RouteForCustomer", "Customer/{Id}", "~/Customer.aspx");

       }


my web page code is:

C#
protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                    string id = Page.RouteData.Values["Id"].ToString();
                    Response.Write("<h1>Customer Details page</h1>");
                    Response.Write(string.Format("Displaying information for customer : {0}", id));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


error is:

object reference not set to an instance of an object. In the line string id in customer.aspx.
Posted

1 solution

You are getting this error because your page is being redirected to the

http://domain/customer.aspx not to the http://domain/customer/1
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900