Error 404 occurs when report loaded

Posted by: chst8937 on 5 November 2024, 10:54 pm EST

    • Post Options:
    • Link

    Posted 5 November 2024, 10:54 pm EST - Updated 6 November 2024, 12:02 am EST

    Hi,

    when I tried to load report,

    http://localhost:0000/InvoiceSystem/Home/InvoiceSystem/api/reporting/reports/Report2.rdlx/info 404 (Not Found)

    this error occurs and the report didn’t load on screen.

    I use ActiveReports .NET (VS 2022),

    and my Program.cs file has

    DirectoryInfo ReportsDirectory =
    	new DirectoryInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? String.Empty, "ActiveReports"));
    // Add services to the container.
    builder.Services.AddLogging(config =>
    {
    	// Disable the default logging configuration
    	config.ClearProviders();
    
    	// Enable logging for debug mode only
    	if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == Environments.Development)
    	{
    		config.AddConsole();
    	}
    })
    				.AddReportViewer()
    				.AddMvc(options => options.EnableEndpointRouting = false);
    
    var app = builder.Build();
    
    // Configure the HTTP request pipeline.
    if (!app.Environment.IsDevelopment())
    {
        app.UseExceptionHandler("/Error");
    }
    app.UseReportViewer(settings =>
    {
        settings.UseFileStore(ReportsDirectory);
    });

    this code, and in controller, I send data

        [Area("InvoiceSystem")]
    	[Route("[area]/[controller]/[action]")]
    	public class HomeController : Controller
    	{
            private static readonly string CurrentDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? System.String.Empty;
            public static readonly DirectoryInfo ReportsDirectory = new DirectoryInfo(Path.Combine(CurrentDir, "ActiveReports"));
            [HttpGet]
    		public ActionResult Index()
    		{
                string[] validFileNames = { "Report2.rdlx" };
    
                var reportsList = GetFileStoreReports(validFileNames);
                var list =  new ObjectResult(reportsList); 
                ViewData["list"] = list;
                return View();
            }

    like this.

    javascript code is here.

                let viewer;
                let reports = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(ViewData["list"]));
                window.onload = function () {
    
                    viewer = createViewer({
                        element: '#viewerContainer'
                    });
                    viewer.openReport("Report2.rdlx");
                };

    also if it needed, in project, this code include.

        <ItemGroup>
    	    <None Include="wwwroot\**\*.*">
    		    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    	    </None>
    	    <None Include="ActiveReports\**\*.*">
    		    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    	    </None>
        </ItemGroup>

    Do I need to set the path somewhere else, or should I create a folder in a specific location?

  • Posted 6 November 2024, 5:02 am EST

    Hi Shawn,

    We tested the same at our end but couldn’t replicate the issue at our end. Please see the attached sample demonstrating the same. If the issue persists at your end, please provide us with a stripped-down and runnable sample replicating the issue or edit the attached sample such that it replicates the issue so that we can investigate the same at our end and get back to you accordingly.

    Attachment: https://drive.mescius.io/download?file=ExternalShare/JSViewer_MVC_Core.zip

  • Posted 6 November 2024, 8:31 pm EST - Updated 7 November 2024, 12:09 am EST

    Hi,

    My file is too big to attach, so here is download link.

    https://drive.google.com/file/d/116xZP2naEtmTplqdmEcUnIHj0g0H_Q08/view?usp=drive_link

    If you have problem with using other drive service(because of company’s security policy), just let me know email or something other way.

    Here is my changes.

    • Program.cs
    • Folder directory (edit Controller, add View-Home folder…)
    • make path(Route : area/controller/action)
    • download new js file from libman.json
    • Use GrapeCity.ActiveReports in cshtml file.

    when you start the project, please use this link. (the route that exact I use)

    http://localhost:49726/InvoiceSystem/Home/Index

    Thank you.

  • Posted 7 November 2024, 2:47 am EST - Updated 7 November 2024, 2:52 am EST

    Hi Shawn,

    We are facing Access Denied error while trying to access your drive sample. Could you please provide us with access to the sample so that we may investigate it further?

  • Posted 7 November 2024, 2:50 am EST

    Hi, I approved your access request.

  • Posted 7 November 2024, 4:46 am EST

    Hi Shawn,

    Thank you for the access. You need to make the following 3 changes in order to resolve the issue:

    1. Set the url property of reportService to /api/reporting in the LoadingReports.cshtml:
    reportService: {url: '/api/reporting',},
    

    It the correct base URL for API requests that the JSViewer makes when it tries to fetch report data. It will instruct the viewer to make requests to

    http://localhost:49726/api/reporting/...
    instead of appending it incorrectly as part of an area-specific route (like
    InvoiceSystem/Home/...
    ).

    1. Specify the correct path of reports directory in the Program.cs:
    DirectoryInfo ReportsDirectory =
        new DirectoryInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? String.Empty, "Areas\\InvoiceSystem\\ActiveReports"));
    

    Since your reports are located within the

    Areas\\InvoiceSystem\\ActiveReports
    directory, you need to ensure that the file store has been correctly configured to find your reports.

    1. Changing the route mapping to the following in the Program.cs:
    app.MapControllerRoute(
    	name: "api",
    	pattern: "api/{controller}/{action}/{id?}"
    );
    

    The previous route pattern

    ({area:exists}/{controller=Home}/{action=Index}/{id?})
    made all requests, including API calls, follow the “Area” routing convention. As a result, when the JSViewer made requests like
    api/reporting
    , they were treated as if they were part of the InvoiceSystem area, causing incorrect routing such as
    http://localhost:49726/InvoiceSystem/Home/InvoiceSystem/api/reporting/....
    . Changing to pattern:
    "api/{controller}/{action}/{id?}"
    explicitly maps API requests starting with api/ to their respective controllers without considering the area, ensuring they are handled separately and correctly.

    We hope this helps!

    Regards,



    Katyayny

    UpdatedSample.zip

  • Posted 7 November 2024, 7:50 pm EST

    Hi Katyayny,

    It works. Thank you for helping.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels