什么是URL重写在.NET 4我正在寻找一个简单的解决方案,以重写URL像URL在.NET 4
“myurl.com/ApplicationName/Kohls”的东西是最好的解决方案重写“myurl.com/ApplicationName/index.html?store=Kohls”,所以我可以通过查询字符串访问var“Kohls”。
我目前使用Global.asax,它一直在为上述案件工作 - 但我遇到麻烦的情况下,用户将进入myurl.com/Application,没有“/”或任何事情后应用。
目前,我有这样的:
protected void Application_BeginRequest(object sender, EventArgs e)
{
String CurrentURLPath = Request.Path.ToUpper();
Match nothingAfterRoot = Regex.Match(CurrentURLPath, @"/ApplicationName(/)?$", RegexOptions.IgnoreCase);
if (nothingAfterRoot.Success)
{
HttpContext myContext = HttpContext.Current;
myContext.RewritePath("/ApplicationName/Default.aspx?store=ABC");
}
else
{
Match match = Regex.Match(CurrentURLPath, @"/ApplicationName(/)?(\w)*$", RegexOptions.IgnoreCase);
if (match.Success)
{
CurrentURLPath = CurrentURLPath.Trim('/');
String store= CurrentURLPath.Split("ApplicationName/".ToCharArray())[1];
HttpContext myContext = HttpContext.Current;
myContext.RewritePath(String.Format("/ApplicationName/Default.aspx?store={0}", store));
}
}
}