简体   繁体   English

带有IIS URL重写的虚荣URL

[英]Vanity URLs with IIS URL Rewrite

I feel like this should be easy, but I'm struggling. 我觉得这应该很容易,但是我很挣扎。 I'd like a user to be able to go to this url: 我希望用户能够转到以下网址:

http://www.mysite.com/folder/some-id-text

and have URL Rewrite direct that request here: 并让URL Rewrite在此处直接请求:

http://www.mysite.com/folder/index.aspx?id=some-id-text

http://www.mysite.com/folder/some-id-text should be the only url the user ever sees. http://www.mysite.com/folder/some-id-text应该是用户看到的唯一URL。

in your project edit Global.asax file and add the code below. 在您的项目中,编辑Global.asax文件,然后添加以下代码。

 protected void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes(System.Web.Routing.RouteTable.Routes);
    }

    public static void RegisterRoutes(System.Web.Routing.RouteCollection routes)
    {

        routes.MapPageRoute("somename",
            "folder/{text-id}",
            "~/index.aspx");
    }

then in your index.aspx you can find this variable as 然后在index.aspx中,您可以找到该变量为

 string text_id = RouteData.Values["text-id"].ToString();

further ref http://code.msdn.microsoft.com/Easy-Steps-to-URL-2f792901 进一步参考http://code.msdn.microsoft.com/Easy-Steps-to-URL-2f792901

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM