在我的 ASP.NET Web 应用程序中,我尝试使用 JQuery Ajax 上传文件,该文件又调用.ashx handler
. 文件应保存到pdf
在项目树下创建的文件夹中,使用:
添加 --> 新文件夹
部署和测试时,SaveAs 失败并access is denied
出现错误。
互联网上的所有解决方案都建议对文件夹进行编辑权限。所以在服务器上,我授予用户对文件夹的Network Service
完全控制权,然后上传工作......但问题是Web应用程序的任何后续部署只会删除服务器上的这些权限并且问题当然会返回。pdf
我完全控制Network Service
了Inetpub
文件夹来克服这个问题,这解决了这个问题。但这样做可以接受吗?
感觉不对,所以请您建议什么来解决问题而不是我的解决方法?
处理程序中的代码如下:
public void ProcessRequest(HttpContext context)
{
try
{
if (context.Request.Files.Count > 0)
{
HttpPostedFile postedFile = context.Request.Files[0];
string filePath = context.Server.MapPath("~/pdf");
string fileName = Path.GetFileName(postedFile.FileName);
postedFile.SaveAs( Path.Combine(filePath , fileName) );
string json = new JavaScriptSerializer().Serialize(
new { name = fileName });
context.Response.StatusCode = (int)HttpStatusCode.OK;
context.Response.ContentType = "text/json";
context.Response.Write(json);
context.Response.End();
}
}
catch (Exception e)
{
context.Response.ContentType = "text";
context.Response.Write(e.Message);
context.Response.End();
}
}
提前致谢