如何在不离开C#的当前页面的情况下重写URL?

时间:2013-08-08 08:01:34

标签: c# url-rewriting

我想在不离开当前的情况下重写我的网址。 我发现大量与URL重写相关的帖子,但我没有成功。

如果用户输入此网址,我想要

http://localhost:16185/Company/CareerWebsite.aspx?org_name=hire-people

网址自动转换为此格式 -

http://localhost:16185/hire-people

但原始页面(Company/CareerWebsite.aspx?org_name=hire-people)不会离开。

表示用户在浏览器中看不到原始网址(Company/CareerWebsite.aspx?org_name=hire-people)。用户只能看到/hire-people等虚拟网址。

感谢您的帮助...... !!!

1 个答案:

答案 0 :(得分:0)

好吧,如果你想直接按照你所描述的方式进行,你需要做Redirect 301 or 302。对于url-rewriting,你可能需要为iis安装urlRewrite模块。 到目前为止,您需要在web.config文件中使用以下某种url-rewrite规则:

<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
  <match url="^Company/CareerWebsite\.aspx$" />
  <conditions>
    <add input="{QUERY_STRING}" pattern="^org_name=([^=&amp;]+)$" />
  </conditions>
  <action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
相关问题