I am working on a ASP.NET MVC Web application. I have situation where i want to upload a file using application pool identity instead of Logged user identity. I want to use app pool identity only while uploading Files. All other places ,I want to use Logged user identity Itself. Application is hosted in two servers, Server1 and Server2.Shared folder is located in Server1.
Currently I am uploading Files as shown below
[HttpPost]
public JsonResult Upload()
{
string fileUniqueName = string.Empty;
try
{
for (int i = 0; i < Request.Files.Count; i++)
{
HttpPostedFileBase file = Request.Files[i];
string fileName = file.FileName;
fileUniqueName = string.Format("{0}_{1}_{2}",
Path.GetFileNameWithoutExtension(file.FileName),
DateTime.Now.ToString("yyyyMMdd_HHmmss_FFF"),
Path.GetExtension(file.FileName));
string tempFileUploadFolderPath = ConfigurationManager.AppSettings["TempFolderPath"];
Directory.CreateDirectory(tempFileUploadFolderPath);
string fileFullpath = Path.Combine(tempFileUploadFolderPath, fileUniqueName);
file.SaveAs(fileFullpath);
}
}
catch(Exception)
{
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return new JsonResult
{
Data = ""
};
}
return new JsonResult
{
Data = fileUniqueName
};
}
I have below setting in web.config
<authentication mode="Windows" />
<identity impersonate="true" />
Can anyone help to rewrite above code where File Upload works on Application Pool Identity instead of logged user identity. File is uploading to folder where Application is hosted.