2016-11-22 3 views
0

ファイルをアップロードしようとしています。以下のコードはローカルマシン上で動作しますが、コマンドラインからdllを実行しているリモートサーバー上で実行していますが、テスト環境に公開してiisで実行すると失敗します。ファイルをアップロードするASPコアIIS

<form method="post" asp-action="Upload" asp-controller="Prebook" enctype="multipart/form-data"> 
    <div class="form-inline"> 
     <div class="col-md-2"> 
      <div class="form-group"> 
       <input type="file" name="files" data-input= "false" multiple class="filestyle" data-buttonName="btn-primary"> 
      </div> 
     </div> 
     <div class="col-md-2"> 
      <div class="form-group"> 
       <input type="submit" value="Upload File" class="btn btn-primary" /> 
      </div> 
     </div> 
    </div> 
</form> 

コントローラロジック

[HttpPost] 
public async Task<IActionResult> Upload(ICollection<IFormFile> files) 
{ 
    if (await _contextPB.UploadRow.AnyAsync()) 

    {     
     Danger(string.Format("Please LOAD the existing containers before uploading another file"), true); 
     return View(); 
    } 
    int rowCount = 0; 
    var uploads = Path.Combine(_environment.WebRootPath, "uploads"); 
    var _viewModel = new UploadViewModel(); 

    foreach (var file in files) 
    { 

     using (var streamReader = System.IO.File.OpenText(Path.Combine(uploads, file.FileName))) 
     { 
      var line = streamReader.ReadLine(); 
      var columnNames = line.Split(new[] { ',' }); 
      if (!ValidateColumnNames(columnNames)) 
      { 
       Danger(string.Format("Invalid Column Name in Upload file"), true); 
       return View(_viewModel); 
      } 
      while (!streamReader.EndOfStream) 
      { 
       var data = line.Split(new[] { ',' }); 
       var uploadRow = new UploadRow();      
       // validation & assignment logic removed 
       try 
       { 
        _contextPB.Add(uploadRow); 
        rowCount++; 
       } 
       catch (Exception e) 
       { 
        Danger(string.Format("<b>{0},{1}</b> database error", uploadRow.Container_Id, e), true); 
       } 
       line = streamReader.ReadLine(); 

      } 
     } 
    } 
} 

答えて

1

エラーが何であるかを確認するためにcatchブロックを追加してみてください。

私は許可の問題を想定しています。

[HttpPost] 
public async Task<IActionResult> Upload(ICollection<IFormFile> files) 
{ 
    try 
    { 
     if (await _contextPB.UploadRow.AnyAsync()) 
     { 
      Danger(string.Format("Please LOAD the existing containers before uploading another file"), true); 
      return View(); 
     } 

     // your code 
    } 
    catch (Exception ex) 
    { 
     // what is the error? 
     // add a breakpoint to see 
     throw; 
    } 
} 
関連する問題