【问题标题】:IIS URL Rewrite Module rule for aspxaspx 的 IIS URL 重写模块规则
【发布时间】:2014-02-02 17:26:56
【问题描述】:

我的问题很简单,可能会被问到, 我有一个网站www.alovine.com 并有一个网址www.alovine.com/registration.aspx。 现在我希望人们在输入www.alovine.com/registration 时能够打开页面 即最后没有“.aspx”。

我已经搜索过了,但找不到答案。 我曾尝试使用以下方法更改 webconfig:

<rule name="Rewrite ASPX">
    <match url="registration" />
    <action type="Rewrite" url="registration.aspx" />
  </rule>

【问题讨论】:

标签: asp.net iis url-rewriting url-rewrite-module


【解决方案1】:

在您的 Global.asax 上插入此代码:

routes.MapPageRoute("", "{registration}", "~/registration.aspx");

使用上面的代码,您的链接将如下所示:

http://localhost:12345/alovine/registration

希望这会有所帮助!

【讨论】:

  • 感谢您的快速回复,但是将 global.asax 文件放在哪里?在 application.start ??
  • 它说错误 3 当前上下文中不存在名称“路由” C:\Users\Ajiteesh\Desktop\Web\Vine\WebSite3\Global.asax 8 9 WebSite3
  • 您需要实例化 RouteCollection 才能使用 routes 变量,这是一个很好的主题:stackoverflow.com/questions/11704745/…
  • 另外,不要忘记在你的 using 语句中包含 Web.Http 和 Web.Routing
  • 嘿菲利克斯感谢您的帮助,但他理解他说他使用 Page.RouteData.Values["combinedPin"] 解决的方法,但我如何在我的上下文中使用它
猜你喜欢
  • 2012-11-05
  • 2014-10-27
  • 2014-05-01
  • 2011-04-21
  • 1970-01-01
  • 2018-02-01
  • 2014-01-05
相关资源
最近更新 更多