开发者

In MVC3, how do I override the TempDataProvider globally?

I'd like to change the TempDataProvider in an ASP.NET MVC3 application... I know I can do this on each controller by overriding CreateTempDataProvider... but I was wondering if there is a way to do this in 1 spot ("Global.asax?") for all controllers.

My reason is that my site is on a cloud server... and I want to implement the Post-Redirect-Get pattern in 开发者_JAVA技巧some cases, but I don't want the user to be sent to another server and never get his message.


It seems you could write your own ControllerFactory. Here you could then, after retrieving the controller from the base DefaultControllerFactory class, set the TempDataProvider to your implementation. See more details here.
This probably does what you need, but personally I would prefer more then next approach:

I find it a good practice to have all your controllers inherit from some 'base' controller class. Common controller logic (like overriding CreateTempDataProvider can then be done in 1 place.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜