【问题标题】:url rewrite in asp.net for dynamially generated urls在 asp.net 中为动态生成的 url 重写 url
【发布时间】:2014-06-29 04:45:28
【问题描述】:

我几乎没有像http://localhost:35228/begineercontent?name=lanaguages&id=23 这样的动态生成的url,我使用路由来隐藏.aspx 扩展名,现在我想看到上面的url 像这样http://localhost:35228/begineercontent/lanaguages/23 我尝试了一些来自iis url rewrite tool 的url rewrite 方法没有任何工作请帮帮我

【问题讨论】:

    标签: asp.net url-rewriting


    【解决方案1】:

    这可以很容易地完成。您需要在 global.asax 中更改/添加此代码。

    void registerroute(RouteCollection routes)
    {
    
           routes.MapPageRoute("begineercontent", "begineercontent/languages/{Id}", "~/begineercontent.aspx");
     }
    
    void Application_Start(object sender, EventArgs e)
    {
                // Code that runs on application startup
                registerroute(RouteTable.Routes);
    }
    

    您还需要通过添加在 global.asax 中包含正确的程序集

    using System.Web.Routing 
    

    在您的 begineercontent.aspx 中,您需要将此代码添加到页面加载函数中。

    var Id=( Page.RouteData.Values["Id"] as string);
    

    可以在此处找到有关如何使用路由的更详细教程:
    http://msdn.microsoft.com/en-us/library/vstudio/cc668177%28v=vs.100%29.aspx

    【讨论】:

    • 我按照你说的做了,但是 url @user3786513 没有区别
    猜你喜欢
    • 2015-05-07
    • 2012-01-03
    • 2018-12-24
    • 1970-01-01
    • 2012-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-11
    相关资源
    最近更新 更多