0

X509Certificate (.cer) 콘텐츠를 View의 양식에서 데이터베이스로 업로드하는 올바른 방법은 무엇입니까? 나는이 매개 변수가 내 뷰 모델에서ASP.NET MVC 업로드 인증서

<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> 

:

public IFormFile Certificate { get; set; } 

내 컨트롤러가이 IFormFile을 얻는다을,하지만 난에 인증서의 내용을 얻을 수없는 내보기에서

나는이 업로드 입력이 바이트[]. 인증서를 업로드하여이 바이트 배열을 어떻게 얻을 수 있습니까?

+1

[데이터베이스의 X509 인증서 저장] (http://stackoverflow.com/questions/4933759/store-x509-certificate-in-database) –

답변

2

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(); 
    }