This program is blocked by group policy. For more information, contact your system administrator Error in Asp.net core 2.0

Prashant Sharma 66 Reputation points
2021-09-07T17:44:05.267+00:00

My project is in Asp.net core 2.0 and hosted in godaddy windows shared server. I am trying to generate the pdf file in wwwroot/images. In local host file is creating and downloading but after uploading on server i am getting this error

" This program is blocked by group policy. For more information, contact your system administrator', 'System.ComponentModel.Win32Exception (0x80004005): This program is blocked by group policy. For more information, contact your system administrator
at Wkhtmltopdf.NetCore.WkhtmlDriver.Convert(String wkhtmlPath, String switches, String html)"

I have check the folder permission all are given to full control but still getting this error. I am sharing my codes.Kindly help me on same.

web config

   <?xml version="1.0" encoding="utf-8"?>
   <configuration>
      <!-- To customize the asp.net core module uncomment and edit the following section. 
     For more info see https://go.microsoft.com/fwlink/?linkid=838655 -->
     <system.webServer>
          <handlers>
          <remove name="aspNetCore" />
              <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" 
        resourceType="Unspecified"  />
      </handlers>
          <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" 
            stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout">
             <environmentVariables>
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
        <environmentVariable name="ASPNETCORE_HOSTINGSTARTUPASSEMBLIES" value="Microsoft.AspNetCore.ApplicationInsights.HostingStartup" />
        <environmentVariable name="WEBCONNECTION_DETAILEDERRORS" value="1" />
        <environmentVariable name="WEBCONNECTION_USELIVERELOAD" value="False" />
        <environmentVariable name="WEBCONNECTION_OPENBROWSER" value="False" />
        <environmentVariable name="WEBCONNECTION_SHOWURLS" value="False" />
        <environmentVariable name="COMPLUS_ForceENC" value="1" />
           </environmentVariables>
        </aspNetCore>
     </system.webServer>

   <system.web>
   <trust level="Full" originUrl=""/>
</system.web>

   </configuration>

Create file code

    [Route("CreateFile")]
    [HttpPost]
   public async Task<JsonResult> CreateFile(OnlineFormModel model)
   {
      string filePaths = Path.Combine(Directory.GetCurrentDirectory(), $" 
     {webHostEnvironment.WebRootPath}/images", "OnlineForm.pdf");
    try
    {


        if (!string.IsNullOrEmpty(model.HtmlData))
        {

            try
            {

                byte[] pdfData = GenerateFormPdf(model);
                Stream stream = new MemoryStream(pdfData);

                using (var fileStream = new FileStream(filePaths, FileMode.Create))
                {
                    stream.CopyTo(fileStream);
                }
                Global.downloadFilePath = "images/OnlineForm.pdf";                     
            }

            catch (Exception ex)
            {
                Global.SaveError(ex);
                TempData["Message"] = ex.ToString();

            }

        }
    }

    catch (Exception ex)
    {

        Global.SaveError(ex);
        TempData["Message"] = ex.ToString();

    }

    return Json(new Item {  Name = filePaths });
}

---Generate pdf method

 public byte[] GenerateFormPdf(OnlineFormModel model)
  {
    try
      {
          var data= _generatepdf.GetPDF(model.HtmlData);

          return data;

      }
        catch (Exception ex)
      {
        Global.SaveError(ex);
        TempData["Message"] = ex.ToString();
      }

      return null;
  }


Above error is getting on 

var data= _generatepdf.GetPDF(model.HtmlData);

Getpdf is pre defined function of Wkhtmltopdf

csproj code

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
    <PreserveCompilationContext>true</PreserveCompilationContext>
   <MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
    <AspNetCoreModuleName>AspNetCoreModule</AspNetCoreModuleName>
    <!--<AspNetCoreModuleName>AspNetCoreModuleV2</AspNetCoreModuleName>-->

     <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
    <RazorCompileOnPublish>false</RazorCompileOnPublish>

 </PropertyGroup>

 <ItemGroup>
 <Compile Remove="Controllers\DMAController.cs" />
 </ItemGroup>

  <ItemGroup>
  <Content Remove="Views\Home\Index1.cshtml" />
   <Content Remove="Views\Home\Index2.cshtml" />
 <Content Remove="wwwroot\css\style1.css" />
</ItemGroup>

 <ItemGroup>
   <PackageReference Include="ClosedXML" Version="0.95.4" />
    <PackageReference Include="iTextSharp.LGPLv2.Core" Version="1.7.3" />
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.9" />
    <PackageReference Include="Microsoft.AspNetCore.Antiforgery" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Server.IIS" Version="2.2.6" />
    <PackageReference Include="MySql.Data" Version="8.0.25" />
    <PackageReference Include="Select.HtmlToPdf.NetCore" Version="21.1.0" />
    <PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
    <PackageReference Include="Wkhtmltopdf.NetCore" Version="2.0.1" />
   <!--<Content Include=""></Content>-->
   <!--<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.0" PrivateAssets="All" />-->

 </ItemGroup>

 <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.4" />
 </ItemGroup>

 <ItemGroup>
     <None Include="wwwroot\images\banner1.svg" />
    <None Include="wwwroot\images\banner2.svg" />
    <None Include="wwwroot\images\banner3.svg" />
     <None Include="wwwroot\images\banner4.svg" />
    <None Include="wwwroot\js\site.js" />
     <None Include="wwwroot\js\site.min.js" />
 </ItemGroup>

 <ItemGroup>
    <Folder Include="logs\" />
</ItemGroup>

<ItemGroup>
  <None Update="Rotativa\Windows\wkhtmltopdf.exe">
   <CopyToOutputDirectory>Always</CopyToOutputDirectory>
   </None>
</ItemGroup>
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,135 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,198 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 35,031 Reputation points
    2021-09-07T19:23:36.267+00:00

    If you are not part of a Active Directory Group see the following, otherwise as in the message contact the admin for the organization as there are constraints they control as in many organizations/companies for projection against malicious code.

    0 comments No comments