强制小写URL重写的最佳方法是什么?
failed...what我做错了吗?见以下内容:
Global.asax
我不知道该用哪种方法?
void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
string path = Request.Path.ToLower();
context.RewritePath(path);
}web.config
我尝试过使用web.config方法,但无法管理:
<rewrite url="(.*)$" to="$1" permanent="true" />如何更改上述代码,使其自动强制url降大小写?
发布于 2012-05-02 10:38:23
发布于 2012-05-02 09:52:53
在这里,我们没有办法,您可以强迫your user编写小写urls。所有you生成的urls都可以是小写的。如果您在url中获得大写,您可以将用户重定向到小写版本。
void Application_BeginRequest(object sender, EventArgs e)
{
string path = Request.Path;
if (ContainsUpperChars(path))
{
HttpContext.Current.Response.Redirect(Request.Path.ToLower());
}
}
bool ContainsUpperChars(string str) { some code to test for uppercase chars }发布于 2016-02-10 15:30:43
使用web.config中的url重写标记。如果vs2012不识别标签,那么运行在这个页面上找到的脚本:http://blog.vanmeeuwen-online.nl/2013/04/visual-studio-2012-xml-intellisense-for.html这里还有另外两个链接,我用它们来解决问题。ScottGu的‘sBlog和Meligy的博客
<system.webServer>
<rewrite>
<rules>
<rule name="LowerCaseRule" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{URL}}" />
</rule>
</rules>
</rewrite>
</system.webServer>https://stackoverflow.com/questions/10411275
复制相似问题