3

In my ASP.NET MVC3 project, I have a folder called Content (the default folder for an MVC project). But I also have a controller called Content. And when I want to use the default actions of this controller, I simply use http://domain/content/, which is equivalent to http://domain/content/index. But IIS returns 403 error and thinks that I'm gonna get the directory list of the Content Folder. Well, this question is already discussed in this question. But I don't know how to rewrite my URL to append the default action to it. May someone help please.

2
  • 3
    Just avoid using the same names, now you're getting into unnecessary problems that could be avoided other ways. Just rename you Content folder to public or something similar. Commented Jul 10, 2011 at 19:16
  • 2
    Well, I know that. But my question is a general case. What if you encounter a real name collision? Anyway, thank you for mentioning. Commented Jul 10, 2011 at 19:17

2 Answers 2

7

You can get around this by changing routing configuration to specify:

routes.RouteExistingFiles = true;

You will then need to set up some ignore rules to prevent genuine static content being gobbled up by the routing engine.

For example, I have a folder called Touch in my app, and I also have a specific route for Touch. So the working config is:

routes.RouteExistingFiles = true;
routes.IgnoreRoute("Touch/Client/{*touchclientversion}", new { touchclientversion = @"(\d*)(/*)" });

I agree that this kind of thing should generally be avoided, but sometimes it's nice to have pretty URLs :-)

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

Comments

0

You can add a default route like this:

routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );

In your case:

routes.MapRoute(
                "DefaultContent",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Content", action = "Index", id = "" }  // Parameter defaults
            );

2 Comments

Downvote, because I said that I want to rewrite the incoming URL before it maps to route rules. I already have those route rules in action. But IIS StaticHandler takes precedence in responding.
How about mentioning that in the post? Sorry, my mind scanner is not working today.

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.