简体   繁体   中英

Error Generating log file to server network path

When I am running it on debug mode I can successfully write the log file to server path however I don't know why I am getting 500 internal server error on the web console if I am publishing this to my local iis.

Here is my code from backend:

 public static void VerifyDir(string path)
        {
            try
            {
                DirectoryInfo dir = new DirectoryInfo(path);
                if (!dir.Exists)
                {
                    dir.Create();
                }
            }
            catch { }
        }
        public IActionResult storeLogs(string execTime)
        {
            string query = "Test Query statement"
            string path = "//serverPath/Test/Log/";


            VerifyDir(path);
            string fileName = "Track" + "_Logs.txt";

            System.IO.StreamWriter file = new System.IO.StreamWriter(path + fileName, true);
            file.WriteLine(DateTime.Now.ToString() + ": \n" + query + "\n" + execTime + "\n") ;
            file.Close();

            return Ok("ok");
        }

And here is the ajax call from UI:

$.post("/Home/storeLogs", { execTime: 'test123'})                    
    .done(function () {                                                                                  
        console.log("success writing the log");
    });

Is there a difference on the access if debug mode or published? any suggestion/comments TIA.

I think its just because IIS application pool identity don't have permission to access//serverPath. When you debug it in visual studio, application run in IIS express and its identity is your current system logon user. It might be a domain user.

However, when you publish it to local IIS. your application pool will try to access //serverPath via application pool identity. By default application pool don't have permission to access your Server path and the connection get isolated.

So please try to replace the application pool identity to a domain account that have permission to access your //serverpath.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM