0

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:

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.

Brent Barbata
  • 3,631
  • 3
  • 24
  • 23

1 Answers1

1

in your project edit Global.asax file and add the code below.

 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

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

further ref http://code.msdn.microsoft.com/Easy-Steps-to-URL-2f792901

Hemant_Negi
  • 1,910
  • 1
  • 20
  • 25
  • Thank you! This works great for me. I'm always a little hesitant marking answers correct immediately since everyone hasn't had a chance to chime in, but I'll probably mark it correct tomorrow. Thanks again so much for your help! – Brent Barbata Aug 08 '13 at 22:23
  • Also, I needed to change "~/index.aspx" to "~/folder/index.aspx". – Brent Barbata Aug 08 '13 at 22:25