使用MVC路由重定向.aspx网页

时间:2013-09-03 17:55:36

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

我有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事件进行重定向(如果这是最佳方式,请更正我。)
  3. 有兴趣知道这种方式是否可行:

    1. 处理ASP.NET MVC区域(这是我的Web窗体应用程序的一部分)RouteConfiguration?
    2. ISAPI
    3. Web.config / Global.asax
    4. 注意:  这必须是301永久重定向。

1 个答案:

答案 0 :(得分:0)

您可以通过以下方式在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