首页 > 解决方案 > ASP.NET MVC 不良做法:具有可选和必需属性的模型

问题描述

当 Fortify Security 检测到代码时出现上述可能的错误。

我无法理解如何操纵模型以避免可能的错误。可以进行哪些检查来避免错误?

我们如何确定它是否是实际错误。

例如:

public class TestObject
{
        public string ID { get; set; }
        [Required]
        public string Name { get; set; }
        [Required]
        public string TestService { get; set; }
        public int selected { get; set; }

        public TestObject()
        {
        }
}

 [HttpPost, ValidateAntiForgeryToken()]
        public ActionResult TestObject DataModel, string command)
        {
        }
        

由于 TestObject 具有 [Required] 而不是必需的属性。Fortify 可能会引发错误。

标签: c#modelrequiredfortify

解决方案


推荐阅读