"404 - File or directory not found." when run FastReport.NET under an IIS Application: Web

I am testing the FastReport.NET Trial Version.

I have an ASP.NET Core 2 aplication deployed under an IIS Application: WebSite/WebApplication

When I run a FastReport.NET report I get:
Server Error
404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.


and using developer tools in browser I see multiple errors like this one:

HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier).
(XHR)GET - http://server:8001/_fr/preview.getReport?r...;renderBody=yes


I have tried to change RouteBasePath to "/WebApplication/_fr" and this time I get:
Error
404 - Not Found


and using developer tools in browser I see multiple errors like this one:
HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier).
(XHR)GET - http://server:8001/WebApplication/_fr/prev...;renderBody=yes



If I move the ASP.NET app into the root Application of the IIS WebSite or run it under VS2017 IIS Express everything works fine.

How to make it function under WebSite/WebApplication ?

Thank you






Comments

  • edited March 2018
    definitely a bug, but there is a workaround: inject basepath into html/script which is rendered by fastreport

    https://mega.nz/#!Z50wjSZC!GdAffsV6...LxlSHA1xGxOnIaA
  • edited 7:33AM
    ipong wrote: »
    definitely a bug, but there is a workaround: inject basepath into html/script which is rendered by fastreport

    https://mega.nz/#!Z50wjSZC!GdAffsV6...LxlSHA1xGxOnIaA


    The link url is not working.
    What was your workaround solution please? I try inject basepath into HTML/script rendered by fastreport, but after that in page there are additional ajax calls and urls are wrong.
    Thanks.
  • hey, have any progress? cuz I got the same problem...

  • you must have source code to fix the bug

  • To get the Web Root Path try

    In  Core 2.0

      public class HomeController : Controller

      {


        private readonly IHostingEnvironment _hostingEnvironment;

        ..........

         

        public HomeController(IHostingEnvironment hostingEnvironment)

        {

          _hostingEnvironment = hostingEnvironment;

        }


        ....In your code... Index()

        string webRootPath = _hostingEnvironment.WebRootPath; // Get the path to wwwroot folder


    In Core 3 and higher try


      public class HomeController : Controller

      {


        private readonly IWebHostEnvironment _hostingEnvironment;

        ..........


        public HomeController(IWebHostEnvironment hostingEnvironment)

        {

          _hostingEnvironment = hostingEnvironment;

        }

        ....In your code... Index()

        string webRootPath = _hostingEnvironment.WebRootPath; // Get the path to wwwroot folder

  • edited February 2021

    Hello,

    i´m using the current Demo-Version for evalutaion and do have the same problem. Can you please give an solution how to inject the correct path into html or give another solution? I try to use it with AspNet Core 3.1

    best regards

    Volkhard

  • Asp.net Core 2.2 single page application, dont forget to copy folder "Reports" to publish folder😀

  • Asp.net Core 3.1 single page application, dont forget to copy folder "Reports" to publish folder

    <ItemGroup> 
      <Content Include="Reports\**"> 
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 
      </Content> 
    </ItemGroup>
    


  • edited February 2021

    Hello ipong,

    thanks for your fast help :)

    i modified following lines:

    //        string basePath = Request.PathBase.Value.Replace("/", "");

            string basePath = Request.PathBase.Value;

            if (basePath.StartsWith("/"))

            {

              basePath = basePath.Substring(1);

            }

    With this the injection works on a folder-Structure like https://localhost/test/test2 on IISExpress

    When i deploy this to an IIS (windows 2016) into an subfolder test i get an 500-Error on the request

    _fr/preview.getReport?reportId=cf6af2189d4e4a389adaa8d382bc252e&renderBody=yes


    Do you have an idea?

    best regards

    Volkhard

  • just change :

    string basePath = Request.PathBase.Value.Replace("/", "");

    to :

    string path = Request.PathBase.Value;

    string basePath = path.Length == 1 ? "" : path.StartsWith("/") ? path.Substring(1) : path;

  • edited February 2021

    Hello Ipong,

    thanks for your help.

    i changed the code to your sample above - but there is still the http 500-Errorcode at _fr/preview.getReport?reportId=f7d249dbc88145879202c6a1f0a54cc5&renderBody=yes:1 

    Do you have another idea? Maybe one topic is, that directory test2 is converted to an Web-Application?

    best regards

    Volkhard

  • rewrite the code, much cleaner...


    [HttpPost("Report")]

    [Route("Report")]

    public ModelFastReport Report([FromBody] ModelDemo value)

    {

    try

    {

    DataSet data1 = LoadData1();

    List<Category> data2 = LoadData2();


    FastReport.Web.WebReport wr = new FastReport.Web.WebReport();

    string frx = Path.Combine(_env.ContentRootPath, "reports", value.file);

    wr.Report.Load(frx);

    wr.Report.RegisterData(data1, "NorthWind");

    wr.Report.RegisterData(data2, "Categories BusinessObject");

    foreach (FastReport.Data.DataSourceBase item in wr.Report.Dictionary.DataSources)

    {

    item.Enabled = true;

    }

    string basePath = Request.PathBase.Value;

    return new ModelFastReport() { id = basePath, html = FastReportHtml(basePath, wr.ID, wr.RenderSync().Value) };

    }

    catch (Exception ex)

    {

    return new ModelFastReport() { id = "", html = ex.ToString() };

    }

    }


    private string FastReportHtml(string basePath, string token, string htmlString)

    {

    string oldCssOutline = string.Format(".fr{0}-outline {{", token);

    string newCssOutline = string.Concat(oldCssOutline, "color: black;");

    string oldAjax = "container.outerHTML = xhr.responseText";

    string newAjax = string.Format("{0}.replace(\"{1}\", \"{2}\").replace(/\\/_fr/g, \"{3}/_fr\")", oldAjax, oldCssOutline, newCssOutline, basePath);

    string oldCssProgress = "style=\"min-height:200px\">";

    string newCssProgress = string.Format("><img src=\"{0}/progress.gif\">", basePath);

    string OldCssSpinner = string.Format(".fr{0}-spinner {{", token);

    string NewCssSpinner = string.Concat(OldCssSpinner, "display: none;");

    string oldCssBackgroundColor = "background-color: white;";

    return htmlString.Replace("/_fr", basePath + "/_fr").Replace(oldCssBackgroundColor, "").Replace(oldCssProgress, newCssProgress).Replace(OldCssSpinner, NewCssSpinner).Replace(oldAjax, newAjax);

    }

  • but...when you have a report with picture inside, 'print from browser' will not work. thats why in my previous comment, i said "you must have source code to fix the bug"

  • Hello Ipong,

    thanks for your hint.

    i had to publish a selfcontained deployment because on the IIS server is only the .Net Core Hosting-Package installed - but the Solution requires The framework 'Microsoft.WindowsDesktop.App', version '3.1.0' was not found..

    i think this comes from the used Core3-Assemblies. It is possible to get a version, which runs with the .Net Core-Hosting-Package?


    best regards

  • i got the same error, must downgrade to .net core 2.2 => FastReport.Core.2021.1.7-demo.nupkg & FastReport.Web.2021.1.7-demo.nupkg


    It was not possible to find any compatible framework version

    The framework 'Microsoft.WindowsDesktop.App', version '3.1.0' was not found.

     - No frameworks were found.


    You can resolve the problem by installing the specified framework and/or SDK.


    The specified framework can be found at:

      - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.WindowsDesktop.App&framework_version=3.1.0&arch=x64&rid=win10-x64

    It was not possible to find any compatible framework version

    The framework 'Microsoft.WindowsDesktop.App', version '3.1.0' was not found.

     - No frameworks were found.


    You can resolve the problem by installing the specified framework and/or SDK.


    The specified framework can be found at:

      - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.WindowsDesktop.App&framework_version=3.1.0&arch=x64&rid=win10-x64

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.