MVC 控制器 Veracode 错误 915。绑定包括复杂数据类型

问题描述 投票:0回答:0

我正在做一个 Asp.Net Core 2.0 MVC 应用程序。

我在控制器的方法中遇到来自 Veracode 的错误 915。我读了一些文章

我像这样把它付诸实践

[HttpPost("Search")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Search([Bind(include: "SSN,EmployeeNumber,LastName,FirstName")] SearchModel searchModel)

SearchModel
班在哪里

public class SearchModel
    {
        [StringLength(11)]
        [DataType(DataType.Text)]
        public string SSN { get; set; } = string.Empty;
        [MaxLength(20)]
        [DataType(DataType.Text)]
        public string EmployeeNumber { get; set; } = string.Empty;
        [MaxLength(20)]
        public string LastName { get; set; } = string.Empty;
        [MaxLength(20)]
        [DataType(DataType.Text)]
        public string FirstName { get; set; } = string.Empty;
}

效果很好。

我现在遇到的问题,当我作为参数获取的类包含其他类作为属性时,我不知道如何使用它

[HttpPost("Update")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Update(UpdateModel model)
{}

UpdateModel
在哪里

public class UpdateModel
    {
        public Participant? ParticipantInfo { get; set; }
        public List<SpecificFieldsModel>? ParticipantSpecificFields { get; set; }
        public List<Affiliate>? Divisions { get; set; }
        public List<Employee>? EmployeeClasses { get; set; }
        public List<StateModel>? States { get; set; }
        public List<DependentNewModel>? Dependents { get; set; }
    }

Divisions、EmployeeClasses、States 等部分类将为空。我用它来填充页面,但在提交时不需要它们。我需要排除那些课程。

如何使用 Bind Include 为

UpdateModel
类只包含我需要的类?

谢谢

c# asp.net-mvc binding veracode
© www.soinside.com 2019 - 2024. All rights reserved.