0

我想知道当我从浏览按钮中选择一个文件时,在我点击上传按钮之前它非常慢。

我的意思是我点击浏览,选择一个文件,在它最终检查是否有我可以上传的文件之前,我可以等待大约 2 分钟才能上传文件。

这在本地运行良好,但在我的服务器上真的很慢。

我正在使用 IIS,所以也许我必须添加一些设置?

这些是我正在使用的代码:

 <asp:Panel ID="PanelAddFiles" runat="server">
        <div class="PanelAddFiles">
            <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="Server" />
            <asp:UpdatePanel ID="UpdatePanelAddFiles" runat="server" ChildrenAsTriggers="true">
                <Triggers>
                    <asp:PostBackTrigger ControlID="LkUpload" />
                </Triggers>
                <ContentTemplate>
                    <asp:AsyncFileUpload runat="server" ID="FileUploadAsync" CssClass="FileUploadAsync"
                        Visible="false" />
                    <asp:LinkButton ID="LkUpload" runat="server" OnClick="LkUpload_Click" Visible="false">Upload</asp:LinkButton>
                </ContentTemplate>
            </asp:UpdatePanel>

        </div>
    </asp:Panel>

这是背后的代码:

protected void LkUpload_Click(object sender, EventArgs e)
    {
        try
        {

            if (FileUploadAsync.FileName != string.Empty)
            // Call a helper method routine to save the file.
            {
                SaveFile(FileUploadAsync.PostedFile);
                GenerateFilesInDateOrder(DirectoryPath);
            }

        }
        catch { }
    }

    void SaveFile(HttpPostedFile file)
    {
        string savePath = "C:\\inetpub\\wwwroot\\Files" + DirectoryPath;
        string fileName = FileUploadAsync.FileName;
        string pathToCheck = savePath + fileName;
        string tempfileName = "";

        if (System.IO.File.Exists(pathToCheck))
        {
            int counter = 2;
            while (System.IO.File.Exists(pathToCheck))
            {

                tempfileName = counter.ToString() + fileName;
                pathToCheck = savePath + tempfileName;
                counter++;
            }

            fileName = tempfileName;

        }
        else
        {
        }

        savePath += fileName;

        FileUploadAsync.SaveAs(savePath);

        //Redirect to the same page after upload a file
        string param = Request.UrlReferrer.Query;
        Response.Redirect("Files.aspx" + param);
    }
4

0 回答 0