【发布时间】:2018-07-28 18:01:47
【问题描述】:
我的场景是:我有一个 ASP.NET WebForm 网站。用户可以在我的网站上创建自己的页面,他们的页面 url 应该是这样的:(MyWebsite.com/UserPage)。但实际上是:(MyWebsite.com/UserPages.aspx?q=UserPage)。这意味着当你输入 url (MyWebsite.com/UserPage) 时它会重写 url 并显示你 (MyWebsite.com/UserPages.aspx?q=UserPage) (但地址栏总是像 (MyWebsite.com/UserPage)。 这是我在“UrlRewriting”类中的代码:
void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
if (app.Request.Path.Contains("/") && !app.Request.Path.Contains(".") && app.Request.Path.IndexOf("/") == app.Request.Path.LastIndexOf("/"))
{
string userPageTitle = app.Request.Path.Substring(app.Request.Path.IndexOf("/") + 1);
if (!string.IsNullOrEmpty(userPageTitle ))
{
app.Context.RewritePath(string.Format("UserPages.aspx?q={0}", userPageTitle));
}
}
}
现在这是我的问题:正如我所说,我的项目是 ASP.NET WebForm,(所以,所有页面都有 .aspx 扩展名)我想删除我的 Urls 中的 .aspx 扩展名,我已经在 web 中尝试了一些代码.config 工作正常(在正常情况下),但在我的情况下,如果您输入(MyWebsite.com/UserPage),它将将此“UserPage”视为“UserPage.aspx”。我该如何处理?
【问题讨论】:
标签: asp.net url-rewriting webforms asp.net-webpages