dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.36k stars 9.99k forks source link

NavigationException raised when using NavigationManager.NavigateTo upon form post in SSR #50478

Closed blissvalley closed 1 year ago

blissvalley commented 1 year ago

Is there an existing issue for this?

Describe the bug

NavigationException raised when using NavigationManager.NavigateTo upon form post in server-side rendering

Expected Behavior

redirect page to destination

Steps To Reproduce

@page "/admin_login"
@attribute [StreamRendering(true)]

@using Models
@inject NavigationManager Navigation

<h3>AdminLogin</h3>

<EditForm Model="loginRequest" OnValidSubmit="ProcessLogin" FormName="AdminLoginForm">
    <div class="form-group">
        <label for="password" class="form-label">Password:</label>
        <InputText id="password" class="form-control" @bind-Value="@loginRequest.Password" type="password" />
    </div>
    <div class="mb-2">
        <button type="submit" class="btn btn-primary">Login</button>
    </div>

</EditForm>

@if (errorMessage != null)
{
    <div class="alert alert-danger" role="alert">
        @errorMessage
    </div>
}

@code {

    [SupplyParameterFromForm]
    private LoginRequest loginRequest { get; set; } = new();

    private string? errorMessage { get; set; } = null;

    private void ProcessLogin()
    {

        if (loginRequest.Password == "123")
        {
            Navigation.NavigateTo("/admin"); //Exception Raised
        }
        else
        {
            errorMessage = "Invalid password";
        }
    }

}

Exceptions (if any)

No response

.NET Version

8.0.100-preview.7.23376.3

Anything else?

No response

marinasundstrom commented 1 year ago

This seems like an issue that I have encountered.

The NavigationManager not being for SSR.

From what I heard it should be fixed. Perhaps not released yet.

marinasundstrom commented 1 year ago

Duplicate? https://github.com/dotnet/aspnetcore/issues/49670

Although, I can't reproduce it with the specified SDK version.

Not with my own code, or with the code provided.

marinasundstrom commented 1 year ago

This one seems more likely: https://github.com/dotnet/aspnetcore/issues/50260

mkArtakMSFT commented 1 year ago

Thanks for contacting us. Does this exception result in an error in application or does it simply go away after you Continue debugging (F5) ?

ghost commented 1 year ago

Hi @blissvalley. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

danroth27 commented 1 year ago

I'm unable to reproduce this exception with .NET 8 RC1.

ghost commented 1 year ago

Thank you for filing this issue. In order for us to investigate this issue, please provide a minimal repro project that illustrates the problem without unnecessary code. Please share with us in a public GitHub repo because we cannot open ZIP attachments, and don't include any confidential content.

blissvalley commented 1 year ago

Thanks for contacting us. Does this exception result in an error in application or does it simply go away after you Continue debugging (F5) ?

When continue using F5, the program continue and go to destination page successfully.

javiercn commented 1 year ago

@blissvalley thanks for the additional details.

That exception is launched and caught internally by the framework, the behavior is by design. You can avoid pausing on it if you turn off first chance exceptions