asp.net-core

How do I detect mobile devices in blazor server side application?

安稳与你 提交于 2021-02-10 18:29:26
问题 I need to detect if the user of my blazor server side application is using a mobile device. Is there any way to find out which device the user is using? I know I can do it with a JSRuntime but is there any way to figure it out with pure C#? 回答1: I did find this article that will read you the width and height of a window in Blazor. Looks like it uses JS Interop. With that, you can determine if a user is using a mobile based on the width of their resolution. Of course, it's not 100% full proof

Response object is null when using FeatureCollection on the DefaultHttpContext

眉间皱痕 提交于 2021-02-10 18:27:05
问题 I am testing some .net Core middleware and would like to run the middleware with the whole asp.net Core http pipeline instead of mocking it. The problem is that somehow the Response object is not being set in the httpRequest when I use the Feature Collection and it is read only on the Request itself. This code throws an exception when it tries to write to the Response Stream. var fc = new FeatureCollection(); fc.Set<IHttpRequestFeature>(new HttpRequestFeature { Headers = new HeaderDictionary

How to access a one of the asp.net core controller action view into an iframe using react application?

旧城冷巷雨未停 提交于 2021-02-10 18:04:22
问题 When iam trying to access one of the asp.net core application controller view from react application, In the browser console iam getting eror like 'Refused to display 'http://localhost:1212/Account/Login/?ReturnUrl=%Home%MyIFrame%3url%TestData' in a frame because it set 'X-Frame-Options' to 'sameorigin'. ' since i am decorated action method with [Authorize] attribute In startup.cs file was included Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory){ app

How to access a one of the asp.net core controller action view into an iframe using react application?

女生的网名这么多〃 提交于 2021-02-10 17:59:29
问题 When iam trying to access one of the asp.net core application controller view from react application, In the browser console iam getting eror like 'Refused to display 'http://localhost:1212/Account/Login/?ReturnUrl=%Home%MyIFrame%3url%TestData' in a frame because it set 'X-Frame-Options' to 'sameorigin'. ' since i am decorated action method with [Authorize] attribute In startup.cs file was included Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory){ app

How to access a one of the asp.net core controller action view into an iframe using react application?

ε祈祈猫儿з 提交于 2021-02-10 17:59:03
问题 When iam trying to access one of the asp.net core application controller view from react application, In the browser console iam getting eror like 'Refused to display 'http://localhost:1212/Account/Login/?ReturnUrl=%Home%MyIFrame%3url%TestData' in a frame because it set 'X-Frame-Options' to 'sameorigin'. ' since i am decorated action method with [Authorize] attribute In startup.cs file was included Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory){ app

Invalid Token - The audience 'empty' is invalid

走远了吗. 提交于 2021-02-10 15:43:09
问题 I have the following Identity Server 4 configuration on ASP.NET Core 3.1 projects: services .AddIdentityServer(y => { y.Events.RaiseErrorEvents = true; y.Events.RaiseInformationEvents = true; y.Events.RaiseFailureEvents = true; y.Events.RaiseSuccessEvents = true; }) .AddDeveloperSigningCredential() .AddInMemoryPersistedGrants() .AddInMemoryIdentityResources(Config.IdentityResources()) .AddInMemoryApiResources(Config.ApiResources()) .AddInMemoryApiScopes(Config.GetApiScopes())

Invalid Token - The audience 'empty' is invalid

余生长醉 提交于 2021-02-10 15:41:56
问题 I have the following Identity Server 4 configuration on ASP.NET Core 3.1 projects: services .AddIdentityServer(y => { y.Events.RaiseErrorEvents = true; y.Events.RaiseInformationEvents = true; y.Events.RaiseFailureEvents = true; y.Events.RaiseSuccessEvents = true; }) .AddDeveloperSigningCredential() .AddInMemoryPersistedGrants() .AddInMemoryIdentityResources(Config.IdentityResources()) .AddInMemoryApiResources(Config.ApiResources()) .AddInMemoryApiScopes(Config.GetApiScopes())

How to send Parameter/Query in HubConnection SignalR Core 2.1

为君一笑 提交于 2021-02-10 14:50:32
问题 I'm trying to send parameters into connection to signalr Connection = new HubConnectionBuilder() .WithUrl("https://familyapp.azurewebsites.net/StoreHub?token=123") .Build(); await Connection.StartAsync(); In my server side i take this parameter from HttpContext: public override async Task OnConnectedAsync() { var group = Context.GetHttpContext().Request.Query["token"]; string value = !string.IsNullOrEmpty(group.ToString()) ? group.ToString() : "default"; await Groups.AddToGroupAsync(Context

Can't update value: 'Primary Key' has a temporary value while attempting to change the entity's state to 'Modified'

…衆ロ難τιáo~ 提交于 2021-02-10 14:44:39
问题 This is my first ASP .Net Core project. It will hold directors. Each director has a page that shows a list of his/her movies. I have two classes. Movie : public class Movie { public int MovieId { get; private set; } public int DirectorId { get; set; } [Required] public string Title { get; set; } public string Year { get; set; } public string Description { get; set; } } And Director : public class Director { public Director() { Movies = new List<Movie>(); } public int DirectorId { get; private

Response to missing required Properties in ASP.NET Core

白昼怎懂夜的黑 提交于 2021-02-10 14:17:39
问题 Given the following controller: using System.ComponentModel.DataAnnotations; using Microsoft.AspNetCore.Mvc; namespace WebApplication1.Controllers { [Route("api/[controller]")] [ApiController] public class ValuesController : ControllerBase { // POST api/values [HttpPost] public ActionResult<string> Post([FromBody] Model req) { return $"Your name is {req.Name}"; } } public class Model { [Required] public string Name { get; set; } } } if I post an empty body {} , the response is: { "errors": {