question

ariktoledano-5610 avatar image
0 Votes"
ariktoledano-5610 asked ariktoledano-5610 commented

Blazor WASM - cannot pass negative parameter to pages after publish

Hi,
I Blazor WASM .net 6 visual studio 2022
I am trying to pass a negative parameter between pages but it doesn't work - it always pass an extra string '%E2%80%8E' at the beginning
for example if I pass -33333
http://localhost:8082/Counter/%E2%80%8E-33333
if I pass positive number then if works
Now the weird thing is that in debug IT DOES WORK :) - http://localhost:8082/Counter/-33333
but when I publish it to IIS then it disrupts the parameter and add the '%E2%80%8E'
this is just an example but In my real app I do pass negative parameter and it breaks it - it used to work on .net core 3.1.

I am adding screen shots to show you the problem +
the code which is basically nothing - I modified the 2 files from razor suffix to txt so they can be uploaded
202322-issuepassingnegativeparameter-afterpublish.jpg202277-issuepassingnegativeparameter-indebug-working.jpg
Thanks
Arik

202255-counter.txt


dotnet-aspnet-core-blazor
· 10
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

this is the index.razor code:
@page "/"
@inject NavigationManager urlNavigationManager
@inject IJSRuntime JSRuntime

<PageTitle>Test Failure passing negative parameters</PageTitle>

<input id="bnt" type="button" @onclick="ButtonClick" value="Move To"/>

<EditForm Model="@this">
<div>
<span>somenumber:</span>
<InputNumber @bind-Value="SomeNumber" />
</div>
</EditForm>


@code
{
public long SomeNumber { get; set; } = 99999;

 public async void ButtonClick()
 {
     //fails
     urlNavigationManager.NavigateTo($"/Counter/{SomeNumber}");

     //failures samples
     //http://localhost:8082/Counter/%E2%80%8E-33333

     //failes
     // urlNavigationManager.NavigateTo($"/Counter/{SomeId}/true/{SomeNumber}/dummy");
     // urlNavigationManager.NavigateTo($"/Counter/{GetSomeid()}");

 }

}

this is the counter.razor code:
@page "/counter/{somenumber:long}"

<PageTitle>Counter</PageTitle>

<h1>Counter</h1>

<div>@somenumber</div>

@code {

 [Parameter]
 public long somenumber { get; set; }    

 protected override async void OnInitialized()
 {
      
    // await JSRuntime.InvokeVoidAsync("alert", $"someid:{someid},somenumber:{somenumber},shouldrequesttosyncdevice:{shouldrequesttosyncdevice}");
 }

}

0 Votes 0 ·

The %E2%80%8E is the left to right mark. My best guess is the left to right mark came from a copy and paste??? Or perhaps a bug with how the URLs are generated.

0 Votes 0 ·

if you will have a look at the code above -
at index.razor :
urlNavigationManager.NavigateTo($"/Counter/{SomeNumber}");
where SomeNumber is just a long variable - it's dyncamic, no copy paste problem
it works in debug!
it fails after publish to IIS - only after I upgraded to .net 6 - it used to work on .net core 3.1.

very weird



0 Votes 0 ·
AgaveJoe avatar image AgaveJoe ariktoledano-5610 ·

Again, E2 80 8E is the left-to-right control character. Blazor runs in the browser so try a different browser. Also, disable any browser plugins.

1 Vote 1 ·
Show more comments

Try to use the following code, and check whether it works well on IIS:

  urlNavigationManager.NavigateTo("/Counter/-33333");

Besides, whether you are using IIS URL rewrite or not?

0 Votes 0 ·

Thank you I have already done this test and IT DOES work this way -> urlNavigationManager.NavigateTo("/Counter/-33333");
so weird :)

difference here is the the parameter is long - see 'SomeNumber ' variable

public long SomeNumber { get; set; } = 99999;
public async void ButtonClick()
{
//fails
urlNavigationManager.NavigateTo($"/Counter/{SomeNumber}");
...


Another option that didn't work is this (converting the long to string):

public async void ButtonClick()
{
//fails
urlNavigationManager.NavigateTo($"/Counter/{SomeNumber.ToString()}");


That's crazy, by the way it also fails on API calls if I try make a call
say I would make that call it will fail (simple API which also works in debug):
var x = await Http.GetFromJsonAsync<WeatherForecast>($"WeatherForecast/GetById/{SomeNumber}");



0 Votes 0 ·

No URL rewrite - simple publish to IIS

0 Votes 0 ·

1 Answer

ariktoledano-5610 avatar image
0 Votes"
ariktoledano-5610 answered

Refining the scenario Thanks to AgaveJoe

on IIS
- it runs on Edge
- it runs on firefox
- it fails on chrome - even after disabled all plugins - Version 101.0.4951.67 (Official Build) (64-bit)


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.