Can i remove the “default.aspx” from the url?

2019-08-29 13:26发布

When i try remove www from url:

www.jeans.com.vn

the result is: jeans.com.vn/default.aspx.

I don't want the /defaul.aspx too.

How can i remove it?

My code:

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();
}

Thanks for any help!

标签: c# default
1条回答
爷的心禁止访问
2楼-- · 2019-08-29 13:50

Just set Path to empty or "/":

builder.Path = "/";
查看更多
登录 后发表回答