Unplanned
Last Updated: 01 Feb 2024 13:25 by Jessie
Jessie
Created on: 01 Feb 2024 13:25
Category: UI for ASP.NET Core
Type: Bug Report
0
The DeferredScriptFile() method builds the JS file at the root of the application rather than in the application root directory

### Bug report

When the deferred scripts are created, the script source points at the root of the application instead of the application's root directory.

### Reproduction of the problem

Enable the global deferred initialization and call the @(Html.Kendo().DeferredScriptFile()) method.

The rendered script tag is:  <script src="/kendo-deferred-scripts-XXXX.js"></script>

But it must be: <script src="/MyWebsite/kendo-deferred-scripts-XXXX.js"></script>

### Solution:

If you add a tilde in the Url.Content(), the generated script file must be located as expected:

public HtmlString DeferredScriptFile(string nonce = "")
{
           ...
            var scriptResult= hasDeferredScritps ? $@"<script src=""{urlHelper.Content("~/kendo-deferred-scripts-" + guid + ".js")}"" {(string.IsNullOrEmpty(nonce) ? "" : "nonce=" + '"' + nonce + '"')}></script>" : "";
            var styleResult = hasDeferredStyles ? $@"<link href=""{urlHelper.Content("~/kendo-deferred-styles-" + guid + ".css")}"" {(string.IsNullOrEmpty(nonce) ? "" : "nonce=" + '"' + nonce + '"')} rel=""stylesheet""></link>" : "";
            return new HtmlString(scriptResult + System.Environment.NewLine + styleResult);
}

### Environment

* **Telerik UI for ASP.NET Core version: 2023.3.1114
* **Browser:** [all]

0 comments