禁止403-仅启用1个功能

时间:2019-06-24 08:38:52

标签: c# asp.net-mvc http wkhtmltopdf

我当前正在将Web应用程序部署到具有HTTPS证书的Web服务器。 该应用程序可以在服务器上以及在本地网络外部正常运行。 除了1个函数,该函数返回。仅当您不在本地网络中时,才会发生这种情况。如果您直接在服务器上执行此请求,则它会完美运行。

  

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

现在,GeneratePDF函数的确需要对某些文件夹的某些访问权限,因此也许这就是发生此错误的原因,但是我确保向IIS_IUSRS添加权限。

这是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");
    }

编辑:

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

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

window.location.href = appPath + "/TimeRegistration/GeneratePDF?FirstDate=" + firstday + "&LastDate=" + lastday;

0 个答案:

没有答案