blazor-server-side

How to use the HttpContext object in server-side Blazor to retrieve information about the user, user agent

三世轮回 提交于 2020-01-11 13:19:09
问题 IP Address, and such like. Very often when users ask how to do it in Server Blazor app, they are either told that it is not possible, or sometimes offered partial solutions employing JSInterop. But can it be done without resorting to JSInterop ? Here's the answer... 回答1: The fiction that the HttpContext object can't be used with Blazor Server App, has been long propagated in stackoverflow, and it is high time to pension it off. It is true that the HttpContext is not available when a WebSocket

How to refresh a blazor sub/child component within a main/parent component?

不打扰是莪最后的温柔 提交于 2020-01-11 12:43:33
问题 You have a main component and inside the main component you have many sub-components You want to refresh a single subcomponent, rather than the entire screen of the main component, is this possible? 来源: https://stackoverflow.com/questions/59226890/how-to-refresh-a-blazor-sub-child-component-within-a-main-parent-component

SignIn for Blazor Server-Side app not working

99封情书 提交于 2020-01-11 10:17:11
问题 I am building a sample login razor component for an Asp.net core 3.0 Blazor Server-Side app. Whenever the code reaches the SignInAsyc method it just appears to hang or lock-up, as the code ceases further execution. I also tried switching up the logic, by using the PasswordSignInAsync method which gave me the exact same result. All code would execute before that method, but then freeze upon execution of that statement. What am I missing here? Razor component page: <div class="text-center">

onclick method not working in Blazor server-side razor component

走远了吗. 提交于 2020-01-11 07:04:43
问题 I am building a sample razor component, and I can not get my button onclick method to fire. When I click the button nothing happens at all. I have even placed a break point in the method to see if it catches which it doesn't. The component does render, but as I said the LoginUser method doesn't appear run at all when clicking the button. razor componet page: <div class="text-center"> <Login FieldsetAttr="fieldsetAttr" UsernameAttr="usernameAttr" PasswordAttr="passwordInput" ButtonAttr=

Cannot access a disposed object in Blazor Server 3.0

丶灬走出姿态 提交于 2020-01-07 08:24:33
问题 I got a Blazor page with following form submit button <button type="submit" class="btn btn-primary" @onclick="@(async()=> await OnCreateItem())">Create </button> Which calls protected async Task OnCreateItem() { try { var result = await dbMgr.CreateAsync(item); } catch (Exception ex) { Throws ==> Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in

How to set consent cookie in Blazor Server

拈花ヽ惹草 提交于 2020-01-06 04:30:09
问题 I have a Blazor 3.1 App with Identity where I want to implement a cookie consent banner. In classic ASP .NET Core, there is a nice template for a cookie consent banner. @using Microsoft.AspNetCore.Http.Features @{ var consentFeature = Context.Features.Get<ITrackingConsentFeature>(); var showBanner = !consentFeature?.CanTrack ?? false; var cookieString = consentFeature?.CreateConsentCookie(); } @if (showBanner) { <div class="container"> <div id="cookieConsent" class="alert alert-info alert

Two way databinding to singleton service Blazor Serverside

十年热恋 提交于 2020-01-05 04:34:28
问题 I have been playing with Blazor on the client using Webassembly quite a bit. But I thought I would try the serverside version now and I had a simple idea I wanted to try out. So my understading was that Blazor serverside uses SignalR to "push" out changes so that the client re-renders a part of its page. what I wanted to try was to databind to a property on a singleton service like this: @page "/counter" @inject DataService dataService <h1>Counter</h1> <p>Current count: @currentCount ok</p>

Dynamic method parameter using Blazor Binding [duplicate]

和自甴很熟 提交于 2020-01-05 04:08:09
问题 This question already has answers here : Getting ArgumentOutOfRangeException using for loop in Blazor component (2 answers) Closed 10 days ago . I'm trying to make a paging component by using Blazor. Navigate First , Last , Previous and Next are already working. The problem is: I want the user to be able to click on a page number and the NavigateToPage action to be executed by passing the page number. Here's my attempt: <div class="col-12 col-md-6 col-lg-3 offset-lg-6 text-right"> <nav aria

Blazor: A second operation started on this context before a previous operation completed

时间秒杀一切 提交于 2019-12-29 08:23:06
问题 I'm creating a server side Blazor app. The following code is in the Startup.cs . services.AddDbContext<MyContext>(o => o.UseSqlServer(Configuration.GetConnectionString("MyContext")), ServiceLifetime.Transient); services.AddTransient<MyViewModel, MyViewModel>(); And in the ViewModel: public class MyViewModel : INotifyPropertyChanged { public MyViewModel(MyContext referenceContext) { _myContext = myContext; } public async Task<IEnumerable<Dto>> GetList(string s) { return await _myContext.Table1

Blazor: A second operation started on this context before a previous operation completed

可紊 提交于 2019-12-29 08:23:04
问题 I'm creating a server side Blazor app. The following code is in the Startup.cs . services.AddDbContext<MyContext>(o => o.UseSqlServer(Configuration.GetConnectionString("MyContext")), ServiceLifetime.Transient); services.AddTransient<MyViewModel, MyViewModel>(); And in the ViewModel: public class MyViewModel : INotifyPropertyChanged { public MyViewModel(MyContext referenceContext) { _myContext = myContext; } public async Task<IEnumerable<Dto>> GetList(string s) { return await _myContext.Table1