我正在尝试将一些具有不同扩展名(如 .png、.jpg、.txt、.pdf 等)的文件上传到 IIS 服务器。但是我的所有文件都是根据给定路径创建的,但它们都是 1kb 大小,当你打开他们说
The original file is in the temp folder. Full path of the file: C:\Temp\xxxxxxxxx.tmp
当从源代码运行时,我的代码在本地主机上运行完美,并且在 Web 服务器的目录中没有消息中提到的这样的文件夹。
我的代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileUploadTest.aspx.cs" Inherits="FileUploadTest" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" Multiple="Multiple" name="okantestfileupload" runat="server" />
<asp:Button ID="btnFileUpload" OnClick="btnFileUpload_Clickk" runat="server" Text="ekle" Width="150px" CssClass="CommandButton" />
<asp:ListBox runat="server" ID="ListBoxForInfo" Width="400" CssClass="NormaltextBox" ></asp:ListBox>
</div>
</form>
</body>
</html>
.cs部分
protected void btnFileUpload_Clickk(object sender, EventArgs e)
{
string strFolder = @"D:\TEST\";
HttpFileCollection uploadedFiles = Request.Files;
for (int i = 0; i < uploadedFiles.Count; i++)
{
HttpPostedFile uploadedFile = Request.Files.Get(i);
var uFileSize = uploadedFile.ContentLength;
var uFileName = uploadedFile.FileName;
var uContentType = uploadedFile.ContentType;
string uExtension =
System.IO.Path.GetExtension(uploadedFile.FileName);
uploadedFile.SaveAs(strFolder + uFileName);
ListBoxForInfo.Items.Insert(0, uFileName + "." + uContentType + " Boyut: (" + uFileSize + " bytes) yüklendi.");
}
}
我应该怎么做才能解决这个问题?我已经尝试了一些解决方案,包括考虑防病毒程序。
问候
最佳答案
问题是相关应用程序池的托管管道模式配置。应用程序在 v2.0 .NET CLR 版本上运行,但项目是在 .NET 3.5 上构建的。因此,将 Managed PipeLine Mode 从 Classic 更改为 Integrated 在不知道详细机制的情况下无意中解决了问题。项目中使用的其他外部组件可能会出现不兼容问题。目前正在进行全周期测试,但上传问题已修复。
关于c# - 将文件从 asp.net web 窗体项目上传到 IIS 服务器时,原始文件位于临时文件夹中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54826256/