© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•16mo ago
MattHat

Blazor index page captures static files

I am trying to learn .NET Blazor. My aim is to create an question taking app where the correct questionare is rendered by either the root domain ("default questionare" depending on the domain used to access the service), id or slug.

I have
app.UseStaticFiles()
app.UseStaticFiles()
in my pipeline before
app.MapRzorComponents<App>()
app.MapRzorComponents<App>()
but the component is still triggered by static files.

Program.cs
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorComponents();
...
app.UseStaticFiles();
...
app.MapRazorComponents<App>();
...
app.Run();
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorComponents();
...
app.UseStaticFiles();
...
app.MapRazorComponents<App>();
...
app.Run();


Questionare.razor:
@page "/"
@page "/{IdOrSlug}"
...
//markup
...
@code {
    [Parameter]
    public string IdOrSlug { get; set; }

    private Questionnaire _questionnaire;
    private Response _response = new();
    private Dictionary<string, Answer> _answers = new();
    private bool _loading = true;

    protected override async Task OnInitializedAsync()
    {
        _questionnaire = await DatabaseService.GetQuestionnaireByIdOrSlug(IdOrSlug);

        if (_questionnaire == null)
        {
            var uri = new Uri(NavigationManager.Uri);
            Console.WriteLine(uri); // this prints all css assets, favicon.png too etc.
            _questionnaire = await DatabaseService.GetQuestionnaireByDomain(uri.Host); 
        }

        if (_questionnaire != null)
        {
            _response.QuestionnaireId = _questionnaire.Id;
            foreach (var question in _questionnaire.Questions)
            {
                _answers[question.Id] = new Answer { QuestionId = question.Id };
            }
        }

        _loading = false;
    }

    private void HandleRatingChange(string questionId, int rating)
    {
        _answers[questionId].RatingAnswer = rating;
    }

    private async Task HandleSubmit()
}
@page "/"
@page "/{IdOrSlug}"
...
//markup
...
@code {
    [Parameter]
    public string IdOrSlug { get; set; }

    private Questionnaire _questionnaire;
    private Response _response = new();
    private Dictionary<string, Answer> _answers = new();
    private bool _loading = true;

    protected override async Task OnInitializedAsync()
    {
        _questionnaire = await DatabaseService.GetQuestionnaireByIdOrSlug(IdOrSlug);

        if (_questionnaire == null)
        {
            var uri = new Uri(NavigationManager.Uri);
            Console.WriteLine(uri); // this prints all css assets, favicon.png too etc.
            _questionnaire = await DatabaseService.GetQuestionnaireByDomain(uri.Host); 
        }

        if (_questionnaire != null)
        {
            _response.QuestionnaireId = _questionnaire.Id;
            foreach (var question in _questionnaire.Questions)
            {
                _answers[question.Id] = new Answer { QuestionId = question.Id };
            }
        }

        _loading = false;
    }

    private void HandleRatingChange(string questionId, int rating)
    {
        _answers[questionId].RatingAnswer = rating;
    }

    private async Task HandleSubmit()
}


Thanks for the help!
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Blazor Wasm Static Content Error
C#CC# / help
11mo ago
blazor implementing 404 page
C#CC# / help
3y ago
Static files asp.net
C#CC# / help
3y ago
Redirect after form POST Blazor Static
C#CC# / help
2y ago