【问题标题】:Redirect .aspx webpage using MVC routing使用 MVC 路由重定向 .aspx 网页
【发布时间】:2013-09-07 01:25:05
【问题描述】:

我有 ASP.NE Web Forms 应用程序,其中有 ASP.NET MVC 区域(带有 razor 视图引擎)

我在这个位置有一个 aspx 页面project/pages/email.aspx 不知何故,无论是来自爬虫代理还是某些用户,他们都能够请求http://wwww.mydomain.com/pages/email.aspx?param1=2&param2=3

我想将此类请求重定向到“PageNotFound

以下不是选项:

  1. 删除该页面:因为该 aspx 页面在我的应用程序中用于其他目的。
  2. 没有兴趣对 PageLod 事件进行重定向(如果这是最好的方法,请纠正我。)

想知道这种方式是否可行:

  1. 处理 ASP.NET MVC 区域(我的 Web 窗体应用程序的一部分)RouteConfiguration?
  2. ISAPI
  3. Web.config / Global.asax

注意: 这必须是 301 永久重定向。

【问题讨论】:

  • 谁对这个问题投了反对票,我感谢你的 cmets 反对。
  • 这是个好问题 +1

标签: asp.net asp.net-mvc webforms asp.net-mvc-routing


【解决方案1】:

您可以在 web.config 中执行此操作,方法如下:https://stackoverflow.com/a/10400010/412451

在你的情况下,它看起来像

<configuration>
  <location path="email.aspx">
    <system.webServer>
      <httpRedirect enabled="true" destination="http://domain.com/PageNotFound.aspx" httpResponseStatus="Permanent" />
    </system.webServer>
  </location>
</configuration>

您也可以查看 IIS 中的 URL Rewrite module

【讨论】:

  • 在我的情况下,我只想在请求来自 MVC 区域而不是来自主应用程序的情况下重定向。那么我应该在我的 ASP.NET MVC 区域文件夹中创建一个 WEB.config 并在那里添加这个 httpRedirect 吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-06-16
  • 1970-01-01
  • 2014-09-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多