asp.net-core-3.0

Connect a JWT to the User property in the Controller

☆樱花仙子☆ 提交于 2019-12-13 03:37:56
问题 I have a Web API .NET Core 3.0 Service. It gets a header that contains a JWT with claims. I added the following to ConfigureServices in Startup.cs to map my JWT to the .NET Core Authentication system: services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(configureOptions => { configureOptions.Events = new JwtBearerEvents() { OnMessageReceived = context => { context.Token = context.HttpContext.Request.Headers["X-JWT-Assertion"]; return Task.CompletedTask; } }; }); I

Issue in System.Reflection.MethodBase.Invoke when debugging ASP.NET Core 3 in Visual Studio 2019

你离开我真会死。 提交于 2019-12-13 02:43:53
问题 I am writing an ASP.NET Core 3 Razor Page app in VS2019. I have started to get a message, "To prevent an unsafe abort when evaluating the function 'System.Reflection.MethodBase.Invoke' all threads were allowed to run..." Can someone tell what is going on and how to resolve it? Thanks 来源: https://stackoverflow.com/questions/58793111/issue-in-system-reflection-methodbase-invoke-when-debugging-asp-net-core-3-in-vi

Visual Studio 2019: Error pop-up appears: “To prevent an unsafe abort when evaluating the function…”

夙愿已清 提交于 2019-12-11 16:34:37
问题 I am facing an issue with Visual Studio 2019 (version 16.3.8), when starting an ASP.NET Core 3 WebApi project. After clicking OK the project starts and runs without any issue. However the pop-up keeps nagging me every time I have to start my solution. How can I stop showing it? What is it trying to tell me anyway? 回答1: There seems to be two possible solutions to this, that at least worked for me being on Visual Studio 2019. Solution Goto Tools => Options => Debugging => General and then

Server Side Blazor (Preview 6) - is it possible to require authentication for a particular page?

血红的双手。 提交于 2019-12-11 09:53:43
问题 For a Blazor server hosted page - is it possible to require authentication? Based on the following documentation: https://docs.microsoft.com/en-au/aspnet/core/security/authorization/policies?view=aspnetcore-3.0 I've added the following to my Startup.cs : public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion( CompatibilityVersion.Version_2_2 ); services.AddAuthorization(options => { options.AddPolicy("Private", policy => policy

Is it possible to change .cshtml View and see the changes instantly using .NET Core?

雨燕双飞 提交于 2019-12-09 03:18:46
问题 Context In my NET Framework 4.x ASP MVC projects, when using the IDE, it was possible to edit a .cshtml View, then save, then press ctrl+F5 in the browser and see the actual change. It seems to be not working in .NET Core (using VS 2019 and .NET Core 3 Preview 5) Question Is this feature missing in .NET Core or is this a preview issue, or am I missing something? 回答1: This is something that is no longer enabled by default as of ASP.NET Core 3, but it can be re-enabled as documented here:

ASP.NET Core 3.0 [FromBody] string content returns “The JSON value could not be converted to System.String.”

北战南征 提交于 2019-12-08 04:37:23
问题 Using [FromBody] string content on an ApiController in ASP.NET Core 3.0 returns a validation error: {"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1", "title":"One or more validation errors occurred.", "status":400, "traceId":"|9dd96d96-4e64bafba4ba0245.", "errors":{"$":["The JSON value could not be converted to System.String. Path: $ | LineNumber: 0 | BytePositionInLine: 1."]}} when the client post data with content-type : application/json How do I get the raw json data as a

Display a timer in Blazor

被刻印的时光 ゝ 提交于 2019-12-08 01:02:13
问题 I am attempting to display a countdown timer in a server-side Blazor app. My code is in both F# and C#. The code somewhat works, but the timer never stops as intended, and the timer display sporadically does not render all of the numbers. This is my first attempt at a Blazor server-side app. I am not sure if the problem is an async issue, timer issue, or rendering issue. Here's my code: F# let private setTimer countDown timeEvent = let timer = new Timer(float countDown * float 1000) let

How to Separate Code From UI In Blazor.Net

心已入冬 提交于 2019-12-07 23:08:51
问题 Reference to this VisualStudioMagazine article, I am trying to have code in a separate file instead of razor view. I tried: @page "/Item" @using WebApplication1.Shared @using WebApplication1.Client.Services; @inject HttpClient Http @inherits ItemComponent @if (ItemList != null) { <table class="table"> <thead> <tr> <th>ID</th> <th>Name</th> <th>Category</th> <th>Metal</th> <th>Price</th> <th>Quantity</th> </tr> </thead> <tbody> @foreach (var item in ItemList) { <tr> <td>@item.ID</td> <td>@item

Modifying a JSON file using System.Text.Json

巧了我就是萌 提交于 2019-12-07 17:47:12
问题 So first off, yes I know you can do this super easily with Newtonsoft, but as I am working with .NetCore 3.0 I am trying to use the new methods for interacting with JSON files (in other words System.Text.Json ) and I refuse to believe that what I am trying to do is all that difficult! My application needs to list users that have not already been added to my database. In order to get the full list of all users, the app retrieves a JSON string from a web api. I now need to cycle through each of

JsonResult(object) causes “The collection type 'Newtonsoft.Json.Linq.JToken' is not supported.”

霸气de小男生 提交于 2019-12-07 15:26:27
问题 I upgraded an existing ASP.NET Core 2.2 project to 3.0. I have a method that returns JSON which worked in 2.2, but in 3.0, it causes "The collection type 'Newtonsoft.Json.Linq.JToken' is not supported." at the return. [HttpGet()] public async Task<JsonResult> Get() { var res = some class object in a third-party library; return new JsonResult(res); } I have searched Google and found that Microsoft has replaced Newtonsoft Json to System.Text.Json , but I have not explicitly used Newtonsoft Json