3

我有一个在global.asax文件中声明的 url 路由:

  routes.MapPageRoute("RouteAdmin", "Admin/{Url}", "~/pages/MyPage.aspx", false);

但是如果用户尝试访问 mysite.com/pages/MyPage.aspx,他仍然可以看到该页面

问题 :

  • 我可以配置路由以便只接受路由路径吗?
4

2 回答 2

1

通过ASP.NET MVC使用未找到的处理程序定义视图,无法直接访问视图:

<system.web>
  <httpHandlers>
    <remove verb="*" path="*.aspx" />
    <add path="*.aspx" verb="*" type="System.Web.HttpNotFoundHandler" />
  </httpHandlers>
</system.web>

<system.webServer>
  <validation validateIntegratedModeConfiguration="false" />
  <handlers>
    <add name="BlockViewHandler" path="*.aspx" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
  </handlers>
</system.webServer>
于 2014-02-06T22:01:38.673 回答
0

Found it.

If I access directly to the aspx file so I can check this prop:

Page.RouteData.RouteHandler is null

where

if I use route url it is not null :

{System.Web.Routing.PageRouteHandler}

Edit

(better solution)

Add those 2 lines to global asax

 routes.MapPageRoute("Route", "{*.}", "~/pages/default.aspx", false );
 routes.RouteExistingFiles = true; 
于 2013-08-13T07:24:31.403 回答