title: 500 Internal Server error on App deployment to live server
body: <p>My ASP.Net web app has a simple ajax file upload on one of the pages which works fine on my local host machine when testing, however when I publish this to a website I get a 500 Internal Server error. Below is the output on the console on Google chrome:</p>
  
  <pre><code>POST http://switchclothing.andrewmwest.co.uk/StoreManager/UploadFiles 500 (Internal Server Error) jquery-2.1.0.min.js:4
  l.cors.a.crossDomain.send jquery-2.1.0.min.js:4
  o.extend.ajax jquery-2.1.0.min.js:4
  send jquery.fileupload.js:834
  $.widget._onSend jquery.fileupload.js:896
  (anonymous function) jquery-ui-1.10.4.js:401
  data.submit jquery.fileupload.js:612
  (anonymous function) jquery.fileupload.js:180
  j jquery-2.1.0.min.js:2
  k.add jquery-2.1.0.min.js:2
  $.widget.options.add jquery.fileupload.js:179
  $.Widget._trigger jquery-ui-1.10.4.js:785
  (anonymous function) jquery.fileupload.js:935
  o.extend.each jquery-2.1.0.min.js:2
  $.widget._onAdd jquery.fileupload.js:928
  (anonymous function) jquery-ui-1.10.4.js:401
  (anonymous function) jquery.fileupload.js:1105
  j jquery-2.1.0.min.js:2
  k.add jquery-2.1.0.min.js:2
  d.always jquery-2.1.0.min.js:2
  $.widget._onChange jquery.fileupload.js:1099
  (anonymous function) jquery-ui-1.10.4.js:401
  handlerProxy jquery-ui-1.10.4.js:702
  o.event.dispatch jquery-2.1.0.min.js:3
  r.handle jquery-2.1.0.min.js:3
  </code></pre>
  
  <p>Clicking on the url for the request I get this error in my browser page:</p>
  
  <pre><code>The resource cannot be found.
  
  Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 
  
  Requested URL: /StoreManager/UploadFiles
  </code></pre>
  
  <p>Ive also attached my code below:</p>
  
  <pre><code>[HttpPost]
          public JsonResult UploadFiles()
          {
              var r = new List&lt;UploadFilesResult&gt;();
  
              foreach (string file in Request.Files)
              {
                  HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
                  if (hpf.ContentLength == 0)
                      continue;
  
                  string savedFileName = Url.Content(Path.Combine(Server.MapPath("~/Images"), Path.GetFileName(hpf.FileName)));
  
                  var path = GetNewPathForDupes(savedFileName);
  
                  hpf.SaveAs(path);
  
                  r.Add(new UploadFilesResult()
                  {
                      Name = "/Images/" + Path.GetFileName(path),
                      Length = hpf.ContentLength,
                      Type = hpf.ContentType
                  });
              }
              return Json(r);
          }
  
          private string GetNewPathForDupes(string path)
          {
              string directory = Path.GetDirectoryName(path);
              string filename = Path.GetFileNameWithoutExtension(path);
              string extension = Path.GetExtension(path);
              int counter = 1;
  
              string newFullPath;
  
              do
              {
                  string newFilename = "{0}({1}){2}".FormatWith(filename, counter, extension);
                  newFullPath = Path.Combine(directory, newFilename);
                  counter++;
              } while (System.IO.File.Exists(newFullPath));
  
              return newFullPath;
          } 
  </code></pre>
  
  <p>My HTML and javascript code:</p>
  
  <pre><code>$(document).ready(function () {
              $('#fileupload').fileupload({
                  dataType: 'json',
                  url: "/StoreManager/UploadFiles",
                  autoUpload: true,
                  done: function (e, data) {
                      var json = data.result[0];
  
                      $("#picurl").val(json['Name']);
  
                      $('.file_name').html(json['Name']);
                      $('.file_type').html(json['Type']);
                      $('.file_size').html(json['Length']);
                  }
              }).on('fileuploadprogressall', function (e, data) {
                  var progress = parseInt(data.loaded / data.total * 100, 10);
                  $('.progress .progress-bar').css('width', progress + '%');
              });
          });
  
  
  @using (Html.BeginForm())
  {
      @Html.AntiForgeryToken()
  
      &lt;div class="form-horizontal"&gt;
          &lt;h4&gt;Footwear&lt;/h4&gt;
          &lt;hr /&gt;
          @Html.ValidationSummary(true)
          @Html.HiddenFor(model =&gt; model.FootwearId)
  
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.Name, new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.EditorFor(model =&gt; model.Name)
                  @Html.ValidationMessageFor(model =&gt; model.Name)
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.Price, new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.EditorFor(model =&gt; model.Price)
                  @Html.ValidationMessageFor(model =&gt; model.Price)
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.FootwearPicUrl, new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.TextBoxFor(model =&gt; model.FootwearPicUrl, new { @id = "picurl", @readonly = "readonly" })
                  @Html.ValidationMessageFor(model =&gt; model.FootwearPicUrl)
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.Colour, new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.EditorFor(model =&gt; model.Colour)
                  @Html.ValidationMessageFor(model =&gt; model.Colour)
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.DepartmentId, "DepartmentId", new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.DropDownList("DepartmentId", String.Empty)
                  @Html.ValidationMessageFor(model =&gt; model.DepartmentId)
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.BrandId, "BrandId", new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.DropDownList("BrandId", String.Empty)
                  @Html.ValidationMessageFor(model =&gt; model.BrandId)
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              &lt;div class="col-md-offset-2 col-md-10"&gt;
                  &lt;input type="submit" value="Save" class="btn btn-default" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  }
  
  &lt;span class="btn btn-success fileinput-button"&gt;
      &lt;i class="glyphicon glyphicon-plus"&gt;&lt;/i&gt;
      &lt;span&gt;Add files...&lt;/span&gt;
      &lt;input id="fileupload" type="file" name="files[]"&gt;
  &lt;/span&gt;
  &lt;br /&gt;
  &lt;div class="progress"&gt;
      &lt;div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;"&gt;
          &lt;span class="sr-only"&gt;0% complete&lt;/span&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;br /&gt;
  &lt;div class="file_name"&gt;&lt;/div&gt;
  &lt;br /&gt;
  &lt;div class="file_type"&gt;&lt;/div&gt;
  &lt;br /&gt;
  &lt;div class="file_size"&gt;&lt;/div&gt;
  </code></pre>