asp.net-core-webapi

run additional logic besides [Authorize] annotation

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-10 00:12:44
问题 I'm using the Microsoft.AspNetCore.Authentication.JwtBearer and System.IdentityModel.Tokens.Jwt for my .NET Core project. Whenever I generate a new token I store that to the database. When a user signs out, I remove it from the database to invalidate it (I also remove the expired ones from the database with a job). When a user tries to access a route protected by the [Authorize] annotation I want to check if that token exists in the database. If not, I send a 401. In my Startup in the

run additional logic besides [Authorize] annotation

好久不见. 提交于 2021-02-10 00:07:43
问题 I'm using the Microsoft.AspNetCore.Authentication.JwtBearer and System.IdentityModel.Tokens.Jwt for my .NET Core project. Whenever I generate a new token I store that to the database. When a user signs out, I remove it from the database to invalidate it (I also remove the expired ones from the database with a job). When a user tries to access a route protected by the [Authorize] annotation I want to check if that token exists in the database. If not, I send a 401. In my Startup in the

How to allow Caching API endpoint that requires Authorization header?

狂风中的少年 提交于 2021-02-09 10:51:39
问题 I was looking at a way for caching responses from an API endpoint developed in .NET Core. The request to the API must have a valid Authorization header as part the requirement. I came across a few articles mentioning that caching wouldn't be possible if the request contains Authorization header, which was a bit of surprise to me. So how should I tackle this problem? Are there any libraries that can possibly enable caching for this kind of scenario? 回答1: For The Authorization header must not

ASP.Net Core Web API custom route not working

白昼怎懂夜的黑 提交于 2021-02-08 19:36:31
问题 I have a ASP.Net Core Web API project, and the following controller: [Route("/api/v0.1/controller")] [ApiController] public class MyController : ControllerBase { [HttpGet("/test")] public ActionResult Test() { return null; } } but when I run the project, at /api/v0.1/controller/test I get "page not found" and I don't see where I made a mistake. 回答1: Your method route template contains prefixed / , due to that, the app route couldn't find the appropriate path. Modify test method route template

How to pass data from a controller to a background service

淺唱寂寞╮ 提交于 2021-02-08 10:20:57
问题 I'm trying to write a simple web api project with a background service executing a method every second. This method loops over a list and just prints out (for the moment) some statistics. I declared a new list in the constructor of the background service. I'm currently encountering some issues with adding and removing items from inside the controller. public UsersController(IUserBackgroundService userService) { private readonly IUserBackgroundService _userService; public UserController

How to consume a web service using .NET Core 2.0 Connected Services

妖精的绣舞 提交于 2021-02-08 07:26:10
问题 I have created a service called GetReportService. My endpoint is http://xxx1/usa/report.asmx. I am using POST passing a parameter id123. How do I invoke this web service using a web api in .NET Core 2.0? 回答1: I figured out that the connected service option is a WCF service so I am able to consume the service as I normally would in previous versions of .NET. However, in .NET Core if I want to inject that service, I do have to go to the Startup.cs file and add my service in the

How to consume a web service using .NET Core 2.0 Connected Services

依然范特西╮ 提交于 2021-02-08 07:24:03
问题 I have created a service called GetReportService. My endpoint is http://xxx1/usa/report.asmx. I am using POST passing a parameter id123. How do I invoke this web service using a web api in .NET Core 2.0? 回答1: I figured out that the connected service option is a WCF service so I am able to consume the service as I normally would in previous versions of .NET. However, in .NET Core if I want to inject that service, I do have to go to the Startup.cs file and add my service in the

OData and .NET Core 2 Web API - disable case-sensitivity?

℡╲_俬逩灬. 提交于 2021-02-08 02:56:16
问题 I'm new to OData, and I'm trying to integrate it into our .NET Core 2.0 Web API using the Microsoft.AspNetCore.OData 7.0.0-beta1 NuGet package. I would like my OData URLs to be case-insensitive (i.e., http://localhost:1234/odata/products would be the same as http://localhost:1234/odata/Products). How can I accomplish this? The relevant portion of my Startup code is as follows: public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,

What is the best way to seed data with a lot of information using EntityFramework Core?

情到浓时终转凉″ 提交于 2021-02-08 02:14:44
问题 I have an entity configuration file and I seed data with the help of HasData , the example below. public class PublicationConfiguration : IEntityTypeConfiguration<Publication> { public void Configure(EntityTypeBuilder<Publication> builder) { builder.Property(p => p.Image) .HasMaxLength(256) .HasDefaultValue("default-publication.png") .IsRequired(); builder.Property(p => p.Title) .HasMaxLength(256) .IsRequired(); builder.Property(p => p.Value) .IsRequired(); builder.Property(p => p.PublisherId

What is the best way to seed data with a lot of information using EntityFramework Core?

给你一囗甜甜゛ 提交于 2021-02-08 02:09:03
问题 I have an entity configuration file and I seed data with the help of HasData , the example below. public class PublicationConfiguration : IEntityTypeConfiguration<Publication> { public void Configure(EntityTypeBuilder<Publication> builder) { builder.Property(p => p.Image) .HasMaxLength(256) .HasDefaultValue("default-publication.png") .IsRequired(); builder.Property(p => p.Title) .HasMaxLength(256) .IsRequired(); builder.Property(p => p.Value) .IsRequired(); builder.Property(p => p.PublisherId