AsyncFileUpload可在我的机器上运行,但不能在服务器上运行

时间:2019-05-06 16:56:48

标签: c# asp.net ajax asyncfileupload

我有一个页面使用AJAX AsyncFileUpload。它在我的计算机上本地工作,但是在尝试上载此错误时在服务器上出现:

    The account used is a computer account. Use your global user account 
    or local user account to access this server.

版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.7.3282.0

感谢您提供有关此问题的任何帮助!

这是asyncfileupload背后的我的aspx.cs代码(在上传时,该文件通过存储过程保存在表中):

protected void AsyncFileUpload_Att_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        try
        {

                    string filename = e.FileName;

                    if (AsyncFileUpload_Att.PostedFile.ContentLength > 2097151)
                    {
                        Label_AttErr.Text = "File must not exceed 2,097,151 KB (2 GB)";
                        return;
                    }
                    else
                        if (Directory.Exists(@"\\svr-cif01\NetStore4\DASTORE1\ORA Project\" + TxtBx_ORAID.Text))
                        {
                        }
                        else { Directory.CreateDirectory(@"\\svr-cif01\NetStore4\DASTORE1\ORA Project\" + TxtBx_ORAID.Text); }

                    string folderPath = (@"\\svr-cif01\NetStore4\DASTORE1\ORA Project\" + TxtBx_ORAID.Text + @"\");

                    //check if exists

                    if (!File.Exists((folderPath) + filename))
                    {
                        AsyncFileUpload_Att.SaveAs((folderPath) + filename);

                        string ext = Path.GetExtension(filename);
                        string contenttype = string.Empty;

                        string strQuery = "Insert INTO dbo.tbl_ProjAttach([ORAID],[FileName],[filePath],[Date], [ProjAttachTypID],[UserName],[Status],[Notes]) values (@ORAID, @FileName ,@filePath, @Date, @ProjAttachTypID, @UserName,  @Status, @Notes)";
                        SqlCommand cmd = new SqlCommand(strQuery);
                        cmd.Parameters.Add("@ORAID", SqlDbType.VarChar).Value = TxtBx_ORAID.Text;
                        cmd.Parameters.Add("@FileName", SqlDbType.VarChar).Value = filename;
                        cmd.Parameters.Add("@filePath", SqlDbType.VarChar).Value = (folderPath + filename);
                        cmd.Parameters.Add("@Date", SqlDbType.VarChar).Value = DateTime.Today.ToString();
                        if (string.IsNullOrEmpty(DropDwn_ProjTyp.Text))
                        {
                            cmd.Parameters.Add("@ProjAttachTypID", DBNull.Value);
                        }
                        else cmd.Parameters.Add("@ProjAttachTypID", SqlDbType.VarChar).Value = DropDwn_ProjTyp.SelectedValue.ToString();
                        cmd.Parameters.AddWithValue("@UserName", SqlDbType.VarChar).Value = txtLogIn.Text;

                        cmd.Parameters.Add("@Status", DBNull.Value);
                        cmd.Parameters.Add("@Notes", SqlDbType.VarChar).Value = TextArea_Att.InnerText;
                        InsertUpdateData(cmd);
                        GridView_Att.DataBind();
                        Label_Saved.Visible = true;
                        Label_Saved.Text = "File uploaded";

                    }
                    else
                    {
                        Label_AttErr.Text = "File ''" + filename + "'' already Exists. Please Rename the file then Attach again.";
                    }

                }


        catch (Exception ex)
        {
            Label_AttErr.Text = ex.Message;
        }

    }

2 个答案:

答案 0 :(得分:0)

我认为您需要包装器保存

using (new ImpersonatedUser(login, domain, password))
{
     save here 
}

答案 1 :(得分:0)

文件上载到的文件夹需要用户IIS_IUSRS的“修改”权限。