VahidN / DNTCaptcha.Blazor

A captcha generator for the Blazor based applications.
Apache License 2.0
33 stars 9 forks source link

Error with DNTCaptcha on a page #4

Closed Fungusware closed 1 year ago

Fungusware commented 1 year ago

When I use DNTCaptcha on my index page (routed as /) everyting works as expected. However when I use it on a page with a route such as /contact I am getting the error below.

[2022-11-15T08:47:57.354Z] Error: Microsoft.JSInterop.JSException: Failed to fetch dynamically imported module: https://localhost:7284/contact_content/DNTCaptcha.Blazor/scripts/dntCaptcha.js TypeError: Failed to fetch dynamically imported module: https://localhost:7284/contact_content/DNTCaptcha.Blazor/scripts/dntCaptcha.js at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args) at DNTCaptcha.Blazor.DntInputCaptcha.LoadScriptsAsync() in F:\Prog\1400\DNTCaptcha.Blazor\src\DNTCaptcha.Blazor\Components\DntInputCaptcha.razor.cs:line 323 at DNTCaptcha.Blazor.DntInputCaptcha.OnAfterRenderAsync(Boolean firstRender) in F:\Prog\1400\DNTCaptcha.Blazor\src\DNTCaptcha.Blazor\Components\DntInputCaptcha.razor.cs:line 305 at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

VahidN commented 1 year ago

contact_content ? How did this happen? You should get the .js file from the root of the domain, such as:

https://localhost:7284/_content/DNTCaptcha.Blazor/scripts/dntCaptcha.js

and not concatenation of the different parts, such as your posted URL:

https://localhost:7284/contact_content/DNTCaptcha.Blazor/scripts/dntCaptcha.js

Because of this line.

Here is a sample to show it in a subdomain with a routed page: https://vahidn.github.io/DNTCaptcha.Blazor/routed-login-page Also you can run it locally if you want.

Fungusware commented 1 year ago

So I have a Contact Form component that I use in both places. On the Index page it works, but not on the Contacts page.

I'm not constructing that URL _content/DNTCaptcha.Blazor/scripts/dntCaptcha.js That is what is being generated.

VahidN commented 1 year ago

I can't reproduce your issue.

Fungusware commented 1 year ago

Does it do the same in Blazor Server ?

VahidN commented 1 year ago

Yes. I updated that sample too. You can download it and test it locally.

Fungusware commented 1 year ago

Can I invite you to my Repo, see if you can see whats going on. I've tried it all.

Your sample worked ok,

VahidN commented 1 year ago

Don't remove the base href from the _Host.cshtml file:

<base href="~/"/>

The is a client side technology that specifies the base URL for all relative URLs in current document.

Fungusware commented 1 year ago

You Sir, are amazing !