Stimulsoft.Reports.Web.NetCore with relative custom PathBase URL

Stimulsoft Reports.WEB discussion
Post Reply
emanuelv
Posts: 20
Joined: Fri Sep 13, 2019 5:46 pm

Stimulsoft.Reports.Web.NetCore with relative custom PathBase URL

Post by emanuelv »

Hello,

I have an interesting issue in which reports will not load if the .NET Core app is deployed to a custom relative URL. For example, it works with http://localhost:50754 but not with http://localhost:50754/testsite/ I have found a very quick way to reproduce the issue. As an example, I am using the SimpleList demo (https://demo.stimulsoft.com/#Net/SimpleList). To run it locally, I published it from the Designer without making any changes to it using the .NET Core and Angular configuration. Running it in Visual Studio and debugging it in IIS Express within Visual Studio works fine. However, it breaks when I make this change:
- Right-click on the NetCoreAngularApplication project in the solution explorer.
- Click on Properties.
- In the Properties window that comes up, on the left side menu, click on Debug.
- Under Web Server Settings at the bottom, the App URL is set to "http://localhost:50754". Change this to anything different like "http://localhost:50754/testsite"
- Run it with IIS Express again. It will deploy the site to http://localhost:50754/testsite. However, when you navigate to the Stimulsoft Report section on the side menu of the webpage, the report does not display. Looking at the debug tools, it is trying to load http://localhost:50754/api/viewer?... from the base URL but it is ignoring the "testsite" portion of the URL. So this is throwing a 404 error on /api/viewer/ itself because http://localhost:50754/api/viewer cannot be found because it really should be http://localhost:50754/testsite/api/viewer.

Is there a way to make it not try to load /api/viewer/ from the base URL but rather the relative URL? I have a workaround that works but was curious if there was more of a formal solution. My workaround is to force the HttpContext PathBase into the CoreRequest object like this:

In ViewerController.cs

Code: Select all

// Setting the required options on the server side
var requestParams = StiNetCoreViewer.GetRequestParams(this);

// -- *** This is one of two lines of code that makes it work: Where the HttpContext that has the PathBase and Path is of type Microsoft.AspNetCore.Http.HttpContext.

requestParams.HttpContext.Request.CoreRequest.Path = HttpContext.Request.PathBase + HttpContext.Request.Path;

if (requestParams.Action == StiAction.Undefined)
{
	var options = new StiNetCoreViewerOptions();

	// -- *** This is the second line of code to make it work. Instead of using GetScriptsResult() with the 'this' controller parameter, use it with the requestParams parameter.
	
	return StiNetCoreViewer.GetScriptsResult(requestParams, options);
}
 return StiNetCoreViewer.ProcessRequestResult(this);
I do see that Stimulsoft.System.Web.HttpRequest builds its own Url object. I used JetBrains dotPeek to peek into this implementation and it looks like it may be missing the PathBase as part of the return statement so that it's something like Scheme + Host + PathBase + Path + QueryString.

Thanks again!
-Emanuel
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: Stimulsoft.Reports.Web.NetCore with relative custom PathBase URL

Post by Lech Kulikowski »

Hello,

The issue is fixed. The fix will be available in the next release build within a week.

Thank you.
emanuelv
Posts: 20
Joined: Fri Sep 13, 2019 5:46 pm

Re: Stimulsoft.Reports.Web.NetCore with relative custom PathBase URL

Post by emanuelv »

Awesome! Thank you so much!
Andrew
Posts: 4104
Joined: Fri Jun 09, 2006 3:58 am

Re: Stimulsoft.Reports.Web.NetCore with relative custom PathBase URL

Post by Andrew »

You are welcome, the release will be in 1-2 weeks.
Post Reply