用C#.net web.config中的-替换Url中的%20 [英] Replace %20 in Url with - in C#.net web.config

查看:60
本文介绍了用C#.net web.config中的-替换Url中的%20的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在C#.net framework = 4.0和Visual Studio版本2010中重写url,我在web.config文件中编写了以下代码行,但它不影响url.我想用-"替换网址中的%20

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> 

在Chrome中,它显示%20,在Mozilla中,它显示"空格,如何用破折号-"替换该空格?

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

推荐答案

更新:

我认为,解决您问题的唯一方法是编写自己的重写模块.这些文章可能会有所帮助:

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

http://www.jphellemons.nl/post/URL-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)|\ )+

例如,应将类似于此 http://www.goo%20le.de/hfdhdhdhd 的网址替换为该 http://www.goo-le.de-/-hfdhdhdhd

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

更新:

它可以在正则表达式测试器中运行 http://regexpal.com/

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

这篇关于用C#.net web.config中的-替换Url中的%20的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆