0

I have a page where I use AJAX AsyncFileUpload. It works locally on my computer, but on the server when I try to upload this error appears:

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

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3282.0

Any help to how to go about this issue is appreciated thank you!

Here is my aspx.cs code behind the asyncfileupload (On upload the file is saved in a table by a stored procedure):

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;
        }

    }
Anderson
  • 117
  • 2
  • 14

2 Answers2

0

I think you need wrapper save this

using (new ImpersonatedUser(login, domain, password))
{
     save here 
}
evilGenius
  • 1,041
  • 1
  • 7
  • 16
0

The folder where the file is uploaded to needs "modify" permissions for the user IIS_IUSRS.

Liquid_IQ
  • 31
  • 2