Click here to Skip to main content
15,884,936 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
Comments
That means Page.RouteData.Values["Id"] is null. Please debug and check.
riodejenris14 6-Aug-13 6:28am    
I know that but i dono how to check and solve the issue!!!

1 solution

If you ignore a mismatch in '}' in your code nothing is wrong here. You only have to write correct URL in the browser -
JavaScript
http://your-domain/Customer/1

Here you need to take care of the Route URL. which refers to Customer so that has to be present in the URL. And, a parameter which refers to the Id.

I hope this helps. :)
Thanks
 
Share this answer
 
v2
Comments
riodejenris14 6-Aug-13 6:38am    
Ya! its working, but how could i load the page initially without the extensions.
Ashutosh Mahto 6-Aug-13 8:27am    
If you want to set the start-up URL while debugging, you can follow this procedure -
1. Select on the Web Project, in solution explorer
2. Right Click -> Properties
3. In Properties window, click onto the Web Tab on the left side.
4. Click on the Start URL radio button. That will enable to start with a desired URL
5. Set url as - http://your-domain/Customer/1
a. If you are using localhost with some port specify it as - http://localhost:56567/Customer/1
b. If you are using Visual Studio Development server and ports are automatically assigned, you can set a fixed port in the same tab's Server section, Specific Port

And DONE!!!! :)

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