question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blazor WebAssembly navigation behaves differently after publish

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Hi,

Why the Blazor WebAssembly application recognizes/navigate to the same url differently before and after publish?

Please find the steps to reproduce below.

Expected Behavior

After click on the “Click me” button response from controller should be displayed when debugging and after publish. OR After click on the “Click me” button Blazor page should be displayed when debugging and after publish

Steps To Reproduce

  1. Create a new Blazor WebAssembly project using Visual Studio 2022
  • Select .NET 6 as Target Framework and Authentication Type as “None”
  • Select all available options (Configure fo HTTPS, ASP.NET Core Hosted, Progressive Web Application, Do not use top-level statements)
  1. Replace code from Counter.razor file in the *.Client project with the following code:
@page "/counter"
@inject NavigationManager navigationManager;

<PageTitle>Counter</PageTitle>
<h1>Counter</h1>
<p role="status">Current count: @currentCount</p>
<a class="btn btn-primary" href="@GetUrl()">Click me</a>

@code {
    private int currentCount = 0;

    private void IncrementCount()
    {
        currentCount++;
    }

    private string GetUrl()
    {
        return navigationManager.BaseUri + "WeatherForecast";
    }
}

Case 1

  1. Build & Run the *.Server project using Visual Studio 2022
  2. Click on the Counter tab
  3. Click on the “Click me” button

Result: JSON response will be displayed in the browser window

Case 2

  1. Build & Publish the *.Server project using Folder Publish Profile Example profile configuration:
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
  <PropertyGroup>
    <DeleteExistingFiles>true</DeleteExistingFiles>
    <ExcludeApp_Data>false</ExcludeApp_Data>
    <LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
    <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <PublishProvider>FileSystem</PublishProvider>
    <PublishUrl>bin\Debug\net6.0\publish\</PublishUrl>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <_TargetId>Folder</_TargetId>
    <SiteUrlToLaunchAfterPublish />
    <TargetFramework>net6.0</TargetFramework>
    <ProjectGuid>ee6cacb6-0f5e-4f9c-ad63-49be7dce6c97</ProjectGuid>
    <SelfContained>false</SelfContained>
  </PropertyGroup>
</Project>
  1. Deploy the published files to IIS or run the application from *.Server.exe file created in publish folder
  2. Go to the application url in a browser
  3. Click on the Counter tab
  4. Click on the “Click me” button

Result: “Sorry, there’s nothing at this address.” message will be displayed.

Additional Step: After the “Sorry, there’s nothing at this address.” is displayed, click CTRL + F5

Result: JSON response will be displayed in the browser window

Exceptions (if any)

No response

.NET Version

6.0.401

Anything else?

obraz obraz obraz obraz obraz

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
javiercncommented, Oct 5, 2022

@Tonrin17 there are two different service-workers used in development and production. They are both in your app, you can check them out. The development service worker just no-ops.

Also debugging might affect the environment since a special version of Edge/Chrome is launched for the debugger to work.

1reaction
Tonrin17commented, Oct 4, 2022

Build & Publish the *.Server project using Folder Publish Profile

I see you’re publishing using the Debug configuration. Are you seeing the same issue if you publish in Release configuration? It shouldn’t make a difference, but would be good to confirm.

Not in this example, but in other project I tried Debug, Release and some other custom configurations. Also have tried runtimes like Portable or Win-x86

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET Core Blazor routing and navigation
This article explains how to manage Blazor app request routing and how to use the NavLink component to create navigation links.
Read more >
Host and deploy ASP.NET Core Blazor WebAssembly
Learn how to host and deploy Blazor WebAssembly using ASP.NET Core, Content Delivery Networks (CDN), file servers, and GitHub Pages.
Read more >
5 Reasons Why You Should Replace the Default ...
This blog explains the reasons and steps to replace the default navigation menu in your Blazor app with the Syncfusion Sidebar component.
Read more >
Avoid 'multi steps refreshing' on page transition in Blazor ...
It means that each component load his content (nearly) independently form other components. Therefore when navigation occurs and the new active ...
Read more >
Cant directly go to a different blazor page : r/dotnet
After you add a new page/component, assuming its page attribute (route) is set properly, if the browser does not get the updated WASM,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found