Replace %20 in Url with - in C#.net web.config

心不动则不痛 提交于 2019-12-13 04:28:55

问题


I am trying to rewrite the url in C#.net framework=4.0 and visual studio version 2010, I have written following line of code in web.config file, but its not affecting the url. I want to replace the %20 in url with "-"

<rewrite>
  <rules>
    <rule name="Myrule">
      <match url="(.)\ (.)" />
      <action type="Rewrite" url="{R:0}-{R:1}" />
    </rule>
  </rules>
</rewrite> 

In Chrome it shows %20 and in Mozilla it shows " " space, how do I replace the space with dash "-"?


回答1:


UPDATE:

I think the only solution for your problem is to write your own Rewrite Module. These article might help:

http://www.upperstrata.com/insights/2010-02-26/using-iis7-url-rewrite-module-with-asp-net-routing/

http://www.jphellemons.nl/post/URL-rewrite-with-aspnet-40-and-IIS7.aspx

I cannot test it and I'm not if it works that way, but try it with another regular expression:

((%20)|\ )+

For example an Url like this http://www.goo%20le.de / hfdhdhdhd should be replaced to this http://www.goo-le.de-/-hfdhdhdhd

Update:

It works in the regular expression tester http://regexpal.com/




回答2:


Maybe try following this tutorial to try developing your own custom rewrite provider.




回答3:


Try this out, Hope this will work.

<%# Server.UrlDecode("www.stack%20overflow.com").Replace("%20", "-") %>


来源:https://stackoverflow.com/questions/16456671/replace-20-in-url-with-in-c-net-web-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!