asp.net-core-2.2

Get version when using IPageRouteModelConvention

时光毁灭记忆、已成空白 提交于 2019-12-10 17:13:55
问题 I sometime ago asked how to add some kind of localized url's, were IPageRouteModelConvention came into play in a, for me, perfect way. With that I'm able to have routes in different languages/names. If I use www.domain.com/nyheter (swedish) or www.domain.com/sistenytt (norwegian) I still only find, in RouteData , that the News route were used ( RouteData.Values["page"] ). How do I get which version? I know I can check/parse the context.Request.Path but am wondering if there is a built-in

Validate values with invalid format in ASP.NET Core API

倖福魔咒の 提交于 2019-12-08 03:58:18
问题 On an ASP.NET Core 2.2 API I have the following action: public async Task<IActionResult> Create([FromBody]Model model) { } Where Model is the following: public class Model { public DateTime? PublishedAt { get; set; } } Property PublishedAt is required and needs to be in the past. When calling the action I am able to predict 2 different scenarios: Data sent to action doesn't include PublishedAt or PublishedAt is NULL. By using DateTime? I am able to check if it is NULL or in the past in case

How to get rid of CORS in .net core 2.2?

回眸只為那壹抹淺笑 提交于 2019-12-07 05:23:59
问题 I've updated my project to .net core 2.2 and it seems like CORS is making problems that weren't there in 2.1. I'm running my app on this URL: http://*:5300 I've added this code in the Startup.cs : public void ConfigureServices(IServiceCollection services) { ... services.AddCors(options => options.AddPolicy("MyPolicy", builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowCredentials() .AllowAnyHeader(); })); services.AddMvc(); ... } public void Configure(IApplicationBuilder app,

Prevent redirect to /Account/Login in asp.net core 2.2

烈酒焚心 提交于 2019-12-07 03:42:06
问题 I am trying to prevent the app to redirect to /Account/Login in asp.net core 2.2 when the user isn't logged in. Even though i write LoginPath = new PathString("/api/contests"); any unauthorized requests are still redirected to /Account/Login This is my Startup.cs: using System; using System.Reflection; using AutoMapper; using Contest.Models; using Contest.Tokens; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Builder;

IConfiguration does not contain a definition for GetValue

断了今生、忘了曾经 提交于 2019-12-06 21:58:00
问题 After moving a class through projects one of the IConfiguration methods, GetValue<T> stopped working. The usage is like this: using Newtonsoft.Json; using System; using System.Net; using System.Text; using Microsoft.Extensions.Configuration; namespace Company.Project.Services { public class MyService { private readonly IConfiguration _configuration; public string BaseUri => _configuration.GetValue<string>("ApiSettings:ApiName:Uri") + "/"; public MyService( IConfiguration configuration ) {

The constraint reference 'slugify' could not be resolved to a type

浪尽此生 提交于 2019-12-06 11:17:34
ASP.NET Core 2.2 has introduced an option for slugifying routing url using Parameter transformer as follows: routes.MapRoute( name: "default", template: "{controller=Home:slugify}/{action=Index:slugify}/{id?}"); I have done the same thing as follows: routes.MapRoute( name: "default", template: "{controller:slugify}/{action:slugify}/{id?}", defaults: new { controller = "Home", action = "Index" }); My routing configuration in the ConfigureServices method as follows: services.AddRouting(option => { option.LowercaseUrls = true; }); but getting the following errors: InvalidOperationException: The

How to fix error “ANCM In-Process Handler Load Failure”?

不打扰是莪最后的温柔 提交于 2019-12-06 06:36:32
问题 I'm setting up the first site in IIS on Windows Server 2016 Standard. This is a NET Core 2.2 application. I cannot get the site to show. I am getting this error : HTTP Error 500.0 - ANCM In-Process Handler Load Failure What can I change to clear this error and get my site to display? My application is a dll . I tested my application on the server through the Command Prompt with dotnet ./MyApp.dll it displays in the browser but only on the server itself with ( localhost:5001/ ). Using this

Prevent redirect to /Account/Login in asp.net core 2.2

北城余情 提交于 2019-12-05 06:18:02
I am trying to prevent the app to redirect to /Account/Login in asp.net core 2.2 when the user isn't logged in. Even though i write LoginPath = new PathString("/api/contests"); any unauthorized requests are still redirected to /Account/Login This is my Startup.cs: using System; using System.Reflection; using AutoMapper; using Contest.Models; using Contest.Tokens; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity;

How to create a LoggerFactory with a ConsoleLoggerProvider?

非 Y 不嫁゛ 提交于 2019-12-03 14:37:55
问题 The ConsoleLoggerProvider has four constructors: ConsoleLoggerProvider(IConsoleLoggerSettings) ConsoleLoggerProvider(IOptionsMonitor<ConsoleLoggerOptions>) ConsoleLoggerProvider(Func<String,LogLevel,Boolean>, Boolean) ConsoleLoggerProvider(Func<String,LogLevel,Boolean>, Boolean, Boolean) Three of them are declared obsolete with this message: This method is obsolete and will be removed in a future version. The recommended alternative is using LoggerFactory to configure filtering and

Can't display static image in the same folder as the component in Angular [closed]

大兔子大兔子 提交于 2019-12-02 23:39:41
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 months ago . In the directory of my component, I've put an image. It's a good, old, plain PNG with a logotyp. So there are four files in there: blobb.png blobb.comp.ts blobb.comp.html blobb.comp.scss In the HTML file, I used a static source link in a default IMG tag like this. <img src="./blobb.png"> I was trying to follow