C# 禁止403-仅在1个功能上

C# 禁止403-仅在1个功能上,c#,asp.net-mvc,http,wkhtmltopdf,C#,Asp.net Mvc,Http,Wkhtmltopdf,我当前正在使用HTTPS证书将我的web应用程序部署到web服务器。 该应用程序可以在服务器上正常运行,也可以在本地网络之外正常运行。 除了返回的1函数。只有当你在本地网络之外时才会发生这种情况。如果您直接在服务器上执行此请求,它将非常有效 Fordbidden 403-您无权访问此服务器上的/SomeFolder/TimeRegistration/GeneratePDF 现在,GeneratePDF函数确实需要一些对某些文件夹的访问权限,所以这可能就是发生此错误的原因,但我确保向IIS_IUS

我当前正在使用HTTPS证书将我的web应用程序部署到web服务器。 该应用程序可以在服务器上正常运行,也可以在本地网络之外正常运行。 除了返回的1函数。只有当你在本地网络之外时才会发生这种情况。如果您直接在服务器上执行此请求,它将非常有效

Fordbidden 403-您无权访问此服务器上的/SomeFolder/TimeRegistration/GeneratePDF

现在,GeneratePDF函数确实需要一些对某些文件夹的访问权限,所以这可能就是发生此错误的原因,但我确保向IIS_IUSR添加权限

这里是GeneratePDF函数

 public ActionResult GeneratePDF(DateTime? FirstDate = null, DateTime? LastDate = null)
    {
        var VendId = Session["VendId"] as string;
        string ShopDoc = "";
        DateTime updatedFirstDate = FirstDate.GetValueOrDefault(DateTime.Now);
        DateTime updatedLastDate = LastDate.GetValueOrDefault(DateTime.Now);
        int weekNum = updatedFirstDate.DayOfYear / 7 + 1;
        var originalCshtml = System.IO.File.ReadAllText(@"C:\somefolder\somefolder\somefolder\Views\PDF\Index.cshtml");

        var myModel = new MyViewModel();
        myModel.TimeRegisters = Utility.Utilities.GetTimeRegisters( updatedFirstDate, updatedLastDate, VendId);
        myModel.WeekNumber = weekNum;
        myModel.ShopDocCode = ShopDoc;
        myModel.GetOrdNr = Utility.Utilities.GetOrdNr(ShopDoc);
        myModel.FromDate = updatedFirstDate;
        myModel.TillDate = updatedLastDate;
        //Update de Timereg -> procesInd = 1.
        var verify = Utility.Utilities.VerifyTimereg(updatedFirstDate, updatedLastDate, VendId);

        var compiledHtml = Engine.Razor.RunCompile(originalCshtml, Guid.NewGuid().ToString(), null, myModel);
        System.IO.File.WriteAllText("C:\\temp\\mypdf.html", compiledHtml);
        try
        {
            var p = Process.Start("C:\\temp\\wkhtmltopdf.exe", "C:\\temp\\mypdf.html C:\\temp\\mypdf.pdf");
            p.WaitForExit(10000);
        }
        catch(Exception ex)
        {
            string path = "C://temp//log.txt";
            if (!System.IO.File.Exists(path))
            {
                // Create a file to write to.
                string createText = "Created Logfile." + Environment.NewLine;
                System.IO.File.WriteAllText(path, createText);
            }
                using (StreamWriter outputFile = new StreamWriter(path, true))
                {
                    string createText = DateTime.Now + " exception: " + ex + " + " + Environment.NewLine;
                    outputFile.WriteLine(createText);
                }
        }

        //    return File("file.pdf", "application/pdf");
        return File("C:\\temp\\mypdf.pdf", "application/pdf", "weeknummer: " + weekNum + ".pdf");
    }
编辑:

我删除了控制器内容,并将其替换为一个简单的返回json 但这给了我完全相同的错误

我认为这与我们到达控制器的方式有关(使用JS的windows位置)


您可能已经检查了日志文件中是否有捕获到的异常?在日志中没有看到任何异常。您将不得不在您身边调试此异常。正如您自己所说,这很可能是操作系统权限问题。检查IIS(或任何Web服务器)和操作系统日志。@ChrisPickford您认为JS Window.location.href会导致错误吗?好像是:/
window.location.href = appPath + "/TimeRegistration/GeneratePDF?FirstDate=" + firstday + "&LastDate=" + lastday;