开发者

ASP.NET Controller name conflicted with a folder name

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 simpl开发者_StackOverflow中文版y 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.


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 :-)


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
            );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜