开发者

Allowing file extensions in MVC3

Hello fellow programmers

I am sitting trying to do something with MVC3. Just exploring the library. Not doing anything fancy. I have created a project and a controller. Now I am trying to let MVC3 to allow me to do fx http://localhost/MyController.json, http://localhost/MyController.xml or just http://localhost/MyController. In the .json and .xml examples I get errors. The third is of course allowed. I have tried to google this, but I do not get anything that helps me.

Can anyone here tell me how to allow file extension in MVC3?

Thanks.

EDIT I开发者_JAVA技巧 have not made any changes to the IIS like mapped file extensions.


You should add a route that includes an extension:

routes.MapRoute("ExtensionRoute",
                "/{controller}.{extension}",
                new { action="Index", extension = UrlParameter.Optional
);

This example maps the extension to a parameter in the action.
You can also make a route with a hard-coded extension.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜