ASP.NET MVC上传证书
ASP.NET MVC upload certificate
从 View 中的表单将 X509Certificate (.cer) 内容上传到数据库的正确方法是什么?
在我看来,我有这个上传输入:
<div class="form-group row">
<label asp-for="Certificates" class="col-sm-2 col-sm-offset-2 form-control-label"></label>
<input type="file" asp-for="Certificates"/>
</div>
在我的 ViewModel 中我有这个参数:
public IFormFile Certificate { get; set; }
我的控制器获取了这个 IFormFile,但是我无法获取 byte[] 中的证书内容。如何通过上传证书得到这个字节数组?
使用接受 IFormFile 参数的操作。
[HttpPost]
public async Task<IActionResult> UploadSomeFile(IFormFile file){
byte[] bytes = new byte[file.Length];
using (var reader = file.OpenReadStream())
{
await reader.ReadAsync(bytes, 0, (int)file.Length);
}
//send bytes to db
return Ok();
}
从 View 中的表单将 X509Certificate (.cer) 内容上传到数据库的正确方法是什么?
在我看来,我有这个上传输入:
<div class="form-group row">
<label asp-for="Certificates" class="col-sm-2 col-sm-offset-2 form-control-label"></label>
<input type="file" asp-for="Certificates"/>
</div>
在我的 ViewModel 中我有这个参数:
public IFormFile Certificate { get; set; }
我的控制器获取了这个 IFormFile,但是我无法获取 byte[] 中的证书内容。如何通过上传证书得到这个字节数组?
使用接受 IFormFile 参数的操作。
[HttpPost]
public async Task<IActionResult> UploadSomeFile(IFormFile file){
byte[] bytes = new byte[file.Length];
using (var reader = file.OpenReadStream())
{
await reader.ReadAsync(bytes, 0, (int)file.Length);
}
//send bytes to db
return Ok();
}