MVC 5 ViewBag安全性 [英] MVC 5 ViewBag security

查看:97
本文介绍了MVC 5 ViewBag安全性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写MVC互联网应用程序的代码,关于使用ViewBag的问题.

I am coding an MVC internet application, and I have a question in regards to using the ViewBag.

在我的许多控制器中,我都有SelectList对象,用户可以在其中选择一个对象.选择的对象是我的模型的外键值.

In many of my controllers, I have SelectList objects, where the user can select an object. The object that is selected is a foreign key value for my model.

我的问题是:我应该为此使用ViewBag吗?ViewBag的安全性如何?我应该在ViewModel中使用值代替ViewBag吗?

My question is this: Should I use ViewBag for this? How secure is the ViewBag? Should I use values in my ViewModel instead of the ViewBag?

谢谢.

推荐答案

使用您的视图模型.

在实施ViewBag(MVC 3)时,动态类型是新的(.NET 4.0),它只是作为ViewData的附带选项使用,还是可以快速生成视图而无需其他类.

When the ViewBag was implemented (MVC 3) dynamic typing was new (.NET 4.0) and it was put in just as a side-option to ViewData or to quickly generate a view without the need for additional classes.

任何认真的MVC项目都将利用具有强类型化视图的模型/视图模型.

Any serious MVC project will take advantage of a model/viewmodel with a strongly typed view.

这两者都没有安全性问题,因为两者本质上仅存在于控制器的使用寿命内.

There are no security concerns with either because both essentially only exist through the controllers lifespan.

这篇关于MVC 5 ViewBag安全性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆