模型状态在部署到生产环境时无效 [英] Model State Invalid when deployed to production enviornment

查看:116
本文介绍了模型状态在部署到生产环境时无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,当我将网站部署到我的生产环境时,我遇到了一个奇怪的问题。在开发期间,当我将表单发布回控制器时,ModelState有效,但在部署到IIS中的生产环境后,在输入完全相同的数据后,ModelState始终无效。有没有人见过这种行为以及我需要做什么来解决它。



感谢您的帮助。

解决方案

这可能是因为您正在连接到Production中的其他数据库,这可能会在运行代码时返回错误/意外的值。


听起来像旧的Works在我的机器上问题。检查生产和开发(测试/验收?)机器的数据库。查看由于日期等文化差异而容易破解的验证。检查机器语言和文化设置,确保您的验证是文化中立的。



希望以上内容可以帮助您,否则您可能想要更新问题并添加一些更详细的信息。



祝你好运!


Hey Guys,我找到了一种方法来查看模型状态中我们实际上无效的属性。希望这有助于其他人....





 ICollection< modelstate> _collection = ModelState.Values; 
foreach (ModelState _modelState in _collection)
{
ModelErrorCollection _errors = _modelState.Errors;
foreach (ModelError _error in _errors)
{
// 写入事件日志等......
}

}

< / modelstate >


Hey guys, I have a strange problem when I deploy my website to my production environment. During development when I post my form back to the controller the ModelState is valid but after deploying to the production enviornment in IIS the ModelState is always invalid after entering in the exact same data. Has anyone seen this behaviour before and any ideas what I need to do to solve it.

Thanks for your help.

解决方案

This could be because you are connecting to a different database in Production and this could be returning wrong / unexpected values while running the code.


Sounds like the old "Works on my machine" problem. Check the database of both production and your development (test/acceptance?) machines. Look at validations that could easily break due to cultural differences like dates for example. Check machine language and culture settings and make sure your validations are culture-neutral.

Hopefully the above helps you out, otherwise you might want to update the question and add some more detailed info.

Good luck!


Hey Guys, I figured out a way to see what properties in the model state we actually invalid. Hope this helps somebody else....


 ICollection<modelstate> _collection = ModelState.Values;
                    foreach (ModelState _modelState in _collection)
                    {
                        ModelErrorCollection _errors = _modelState.Errors;
                        foreach (ModelError _error in _errors)
                        {
                            //write to event log etc......
                        }

                    }

</modelstate>


这篇关于模型状态在部署到生产环境时无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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