[英]File attachments not working after deployment in IIS7
Used below code to attach files. 在下面的代码中用于附加文件。 Its working fine when I run the application from visual studio.
当我从Visual Studio运行应用程序时,它的工作正常。 I deployed the application in IIS7 (in my machine).
我将应用程序部署在IIS7中(在我的机器中)。 From the deployment site, I couldn't able to attach files.
从部署站点,我无法附加文件。 Please let me know how to fix this.
请让我知道如何解决此问题。 View:
视图:
$("#lnkAddAttachment").click(function (e)
{
oFiles = document.getElementById("txtFile").files[0],
nFiles = oFiles.size;
var selectedFile = document.getElementById("txtFile").files[0];
var size = selectedFile.size;
var name = selectedFile.name;
var type = selectedFile.contentDocument;
var xhr = new XMLHttpRequest();
var fd = new FormData();
fd.append("file", document.getElementById('txtFile').files[0]);
xhr.open("POST", "/ESignature/getFile/", true);
xhr.send(fd);
xhr.addEventListener("load", function (event) {
}, false);
var url = '@Url.Content("~/")' + "ESignature/Registration";
$('#gridAttachments').load(url + ' #gridAttachments');
$('#txtDescription').val('');
$('#txtFile').val('');
return false;
})
Controller: 控制器:
[HttpPost]
public ActionResult getFile(HttpPostedFileBase file)
{
BRUser brUser = new BRUser();
AttachedFile attachedFile = new AttachedFile();
attachedFile.FileType = "Passport";
attachedFile.Filename = System.IO.Path.GetFileName(@DateTime.Now.Ticks + file.FileName);
attachedFile.Filesize = (file.ContentLength / 1024);
file.SaveAs(Server.MapPath("~/ESignatureUploads/" + attachedFile.Filename));
attachedFile.Filepath = "~/ESignatureUploads/" + attachedFile.Filename;
if (Session["ESAttachedFiles"] != null)
{
brUser.AttachedFiles = (List<AttachedFile>)Session["ESAttachedFiles"];
}
brUser.AttachedFiles.Add(attachedFile);
Session["ESAttachedFiles"] = brUser.AttachedFiles;
return View("Registration", brUser);
}
[HttpGet]
public ActionResult Registration()
{
BRUser objuser = new BRUser();
if (Session["ESAttachedFiles"] != null)
{
objuser.AttachedFiles = (List<AttachedFile>)Session["ESAttachedFiles"];
TempData.Keep();
}
return View(objuser);
}
In below function, 在下面的功能中
$("#lnkAddAttachment").click(function (e)
I changed the url from 我更改了网址
xhr.open("POST", "/ESignature/getFile/", true);
to 至
xhr.open("POST", "~/ESignature/getFile/", true);
It solved my problem. 它解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.