i have an asp.net mvc app that has a form that uploads a file. On my local box, of course it works fine but when i run it on a remote webserver i get this error:
Exception Details: System.UnauthorizedAccessException: Access to the path 'C:\directory\mytestfile.csv' is denied.
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.
Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
my issue is that i dont know in advance what the file that is going to be upload is (thus the file chooser in the upload screen) so i can't pre authorize it.
here is my code:
Controller Action:
public ActionResult UploadSpreadsheet(HttpPostedFileBase file)
{
var fileName = Path.Combine(Request.MapPath("~/App_Data"), Path.GetFileName(file.FileName));
file.SaveAs(fileName); //This is what blows up . . .
using (CsvReader csv = new CsvReader(new StreamReader(fileName_), true))
{
string[] headers = csv.GetFieldHeaders();
. . . .
View Form:
<form action="/Resources/UploadSpreadsheet" method="post" id="spreadsheetForm" enctype="multipart/form-data">
<fieldset class=outerFieldSet>
<div class="legendTitle">Sync with Spreadsheet</div><hr /><br /><br />
<label>Choose Spreadsheet: </label><input size="88" class="required" type="file" name="file" />
</fieldset>
<input type="submit" class=longButton value="Syncronize Resource Data" />
</form>