Domanda

I have a url route which I declare at global.asax file :

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

But if the user tries to access mysite.com/pages/MyPage.aspx he can still see the page

Question :

  • Can I configure routing so that only routed paths are acceptable ?
È stato utile?

Soluzione 2

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; 

Altri suggerimenti

In ASP.NET MVC views are not accessible directly by defining them using a not found handler:

<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>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top