1

I have the following controller within my MVC project:

public class PressController : Controller
    {
        // GET: Press
        public ActionResult Index()
        {
            return File("../press/FFF_PRESS.zip", ".zip");
        }
    }

My routes

 public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }

When I load the site my URL is as follows:

www.example.com

Which displays the home page correctly, when I click on the following Action <li class="footer__navEl"><a href='@Url.Action("Index", "Press")'>PRESS</a></li>

I would like the URL to be

www.example.com/press 

and return the zip file.

However when I click this Action I get the following:

HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory.

Yet when I specify

www.example.com/press/index

The .zip file is returned correctly.

Now I added the following to my routes.config:

routes.MapRoute("Press", "Press", new { controller = "Press", action = "Index" });

I still get the same error mentioned above, can someone shed some light into what I might be missing to get this to perform correctly?

1
  • Have you setting MapRoute in right order? [domain]/Press will request to show Press directory content, which by default is disabled in IIS. The route order or format should be adjusted so that Press controller evaluated first before default one. Commented Apr 26, 2017 at 1:31

1 Answer 1

3

HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory.

The error indicates you have a physical directory on your web server named press. What is happening is that the web server is returning the directory instead of passing the request on to MVC. The default setting in IIS is not to list the directory's contents, hence the error.

You need to either delete the press directory (recommended), or reconfigure IIS to run the MVC module instead of the directory by using the runAllManagedModulesForAllRequests, which has some caveats.

This isn't a routing problem at all - it is a webserver configuration problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.