Asp.net URL重写(常规表达式)

时间:2010-08-20 17:35:54

标签: asp.net regex url-rewriting

我有像

这样的网址

http://somedomain.com/products.aspx?id=1

我想像

那样改写它

somedomain.com/productname

域上的其余网址在提供时起作用。 喜欢

somedomain.com/forums/categories.aspx

我不想重写这些其他网址。

1 个答案:

答案 0 :(得分:0)

在你的global.ascx文件中这样做

从你重定向的地方,那里的页面你可以这样做

的Response.Redirect( “somedomain.com/productname”);

void Application_BeginRequest(object sender,EventArgs e)     {         string fullOrigionalpath = Request.Url.ToString();

    string[] words = fullOrigionalpath.Split('/');
    string d = words[words.Length-1].ToString();
    if (!d.EndsWith("aspx"))
    {
        Context.RewritePath("/products.aspx?id=1);
    }

}
相关问题