我可以从网址中删除“default.aspx”吗?

时间:2013-02-05 02:58:46

标签: c# default

当我尝试从网址中删除www时:

www.jeans.com.vn

结果是:jeans.com.vn/default.aspx

我也不想要/defaul.aspx

我该如何删除它?

我的代码:

if (Request.Url.Host.StartsWith("www") && !Request.Url.IsLoopback)
{
    UriBuilder builder = new UriBuilder(Request.Url);
    builder.Host = Request.Url.Host.Replace("www.", "");
    Response.StatusCode = 301;
    Response.AddHeader("Location", builder.ToString());
    Response.End();
}

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

只需将Path设为空或“/”:

builder.Path = "/";