没有扩展名的aspx页面的URL重写?

问题描述:

我尝试删除网页的url栏中的.aspx扩展名,但是我的代码显示错误,



global.asax文件:


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:

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:

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;
            }
        }





错误是:



对象引用未设置为对象的实例。在customer.aspx中的行字符串id。



error is:

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

您收到此错误,因为您的页面被重定向到



http://domain/customer.aspx 不是 http:// domain / customer / 1
You are getting this error because your page is being redirected to the

http://domain/customer.aspx not to the http://domain/customer/1