AttributeRouting returns Forbidden when route mirrors directory structure

21 views Asked by At

I'm using MVC 5.2.2 with AttributeRouting.

Imagine the code below, for example:

public sealed class DocumentsController : Controller
{
    [Route("documents")]
    [HttpGet]
    public ActionResult Index()
    {
        return View();
    }
}

This has a route of /documents.

Now, imagine my project has a directory called 'documents' at the root.

IIS will serve me with a 403.14 Forbidden because directory browsing is disabled. It is disabled by design. No, I don't want to enable it.

I assume there may be some kind of Web.config magic that needs to happen.

How can I setup MVC routing to override IIS when there is an applicable route as in this situation, yet continue to serve the IIS level Forbidden when there is not a valid route?

0

There are 0 answers