0

I've successfully managed to route the URL www.mysite.com/home/directory to the home page:

 Routes.MapRoute(
    "forbidden1",
    "{controller}/directory",
    new {                               
       controller = "Home",
       action = "Index",
    });

...but how do I do the same with URL www.mysite.com/directory since mysite.com is home???

IAbstract
  • 19,551
  • 15
  • 98
  • 146

1 Answers1

0

Are you trying to block folder access? If so this is not the correct way to do it.

Code on loan from this answer This will block requests but allow your code to access the folders.

<configuration>
   <system.webServer>
       <security>
          <requestFiltering>
               <hiddenSegments>
                   <add segment="My_Directory" />
               </hiddenSegments>
           </requestFiltering>
       </security>
   </system.webServer>
</configuration>

Edit:

If you want to trap all bad MVC Routes use something like this...

routes.MapRoute(
    "TrapBadRequests",
    "{*url}",
    new { controller = "Home", action = "Default" }
);
Community
  • 1
  • 1
TheNorthWes
  • 2,661
  • 19
  • 35
  • It is a virtual directory - that curious employees may learn of - that already does not allow browsing but I wanted to simply reroute any attempt to view *directory* back to the home page. – IAbstract Jun 20 '14 at 16:49
  • 1
    You can reroute all 404 issues with a web config entry as well. Anyway, I think you just route everything that doesn't map properly. Edited to reflect. – TheNorthWes Jun 20 '14 at 16:53
  • You want to do it as the last 'route' if you can really call it that. Order matters, so if you put this first any request, valid or not, will follow this catch all. – TheNorthWes Jun 20 '14 at 16:57
  • Should minimize the fun those pesky inquisitive employees, like ourselves, will have with your site. Cheers to the weekend. – TheNorthWes Jun 20 '14 at 16:58
  • Still giving me a 403 error. :/ oh well, it's a minor thing for now - I know that people cannot get to the directory without remote perms anyway. – IAbstract Jun 20 '14 at 17:01
  • [It should work, you may have some other route interfering with it.](http://stacoverflow.com/questions/318886/net-mvc-routing-catchall-not-working) – TheNorthWes Jun 20 '14 at 17:08