开发者

Add slashes in Area name on an ASP.NET MVC 2 route

Currently I have an Area in my ASP.NET MVC 2 project call 'API', which is self explanatory.

As the API of my web application matures, I will soon need to add version numbers to my address. ie/

Instead of :

http://site/API/

I will need

http://site/API/1.0/
http://site/API/1.1/
...

What's the best practise to achieve this in ASP.NET MVC (2)?

I'm currently experimenting with an Area call Api_1_0 and modify its MapRoute to

context.MapRoute(
    "Api_1_0_default",
    "Api/1.0/{co开发者_如何学Pythonntroller}/{action}/{id}",
    new { action = "Index", id = UrlParameter.Optional }
);

But appearently the extra slash in the URL causes run time error.


I just tried your exact scenario and it seems to be working just fine with the slash

            context.MapRoute(
                "Api_1_0_default",
                "Api/1.0/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional }
            );

Add slashes in Area name on an ASP.NET MVC 2 route

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜