没有扩展名的aspx页面的URL重写? [英] URL rewriting to be done for aspx page without extension?

查看:106
本文介绍了没有扩展名的aspx页面的URL重写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



global.asax文件:< br $>


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


这篇关于没有扩展名的aspx页面的URL重写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆