asp.net-core-webapi

How to add custom “Cannot deserialize” error message in ASP.NET Core 2

烂漫一生 提交于 2021-02-05 09:27:31
问题 I am building an asp.net-core REST api. How to change the default error: "Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Namespace.Name.Space.Type' because the type requires a JSON object (e.g. {\"name\":\"value\"}) to deserialize correctly. I don't want to expose namespaces or any implementation details with our clients. This error message is added to 400 - Bad Request response, when the client POST an object different from the required JSON. Could be configurable for

How to add custom “Cannot deserialize” error message in ASP.NET Core 2

雨燕双飞 提交于 2021-02-05 09:27:08
问题 I am building an asp.net-core REST api. How to change the default error: "Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Namespace.Name.Space.Type' because the type requires a JSON object (e.g. {\"name\":\"value\"}) to deserialize correctly. I don't want to expose namespaces or any implementation details with our clients. This error message is added to 400 - Bad Request response, when the client POST an object different from the required JSON. Could be configurable for

Cors no-access-control-allow-origin when trying to call B2C login

ぃ、小莉子 提交于 2021-02-04 21:51:02
问题 I cannot resolve this error, i have a .net core web api, with a react application inside of it ( net core react template ) I have also added cors: services.AddCors(options => { options.AddPolicy("AllowMyOrigin", builder => builder.WithOrigins("https://localhost:44300") .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials() ); }); I have tried multiple things but i cant get past this error. I have found loads of material online to try and nothing seems to work i feel like i am missing

Why does Asp.Net Core 2.1 WebApi return a 500.19 error?

独自空忆成欢 提交于 2021-02-04 19:40:09
问题 I have a small webapi service, which works under Visual Studio but doesn't work under IIS. I did the next: New application was added to the default web-site in IIS console. Application was published into app folder from VS via File System (Framework-dependent and Portable options were selected). When I try access folder with my app (like http://localhost/example/ ) I receive 500.19 error with code 0x8007000d . I read this error can happen if ApplicationHost.config or Web.config has wrong XML

Asp.Net Core 3 graceful shutdown throws OperationCanceledException

ぃ、小莉子 提交于 2021-02-04 16:45:31
问题 I'm trying to gracefully terminate a ASP.Net Core 3.1 service (which will run in Kubernetes). When Kubernetes stops a service, it will send a SIGTERM event to the application, at which point I want in-flight requests to complete (which may take several seconds) before terminating... I think I can catch this in a hostedservice, as below, and hence not stop immediately. The following works, but with a timeout of 5 seconds or longer, I receive an OperationCanceledException. Could anyone shed any

TypeError: Cannot read property 'map' of undefined on tsx file

最后都变了- 提交于 2021-01-29 15:29:58
问题 ActivityListItemAttendees interface IProps { attendees: IAttendee[] } export const ActivityListItemAttendees: React.FC<IProps> = ({attendees}) => { return ( <List horizontal> {attendees.map(attendee => ( <List.Item key={attendee.username}> <h1>{attendee.displayName}</h1> </List.Item> ))} </List> ); } ActivityListItem const ActivityListItem: React.FC<{activity: IActivity}> = ({activity}) => { return ( <Segment.Group> <Segment> <Item.Group> <Item> <Item.Image size='tiny' circular src='/items

Alternative Save/OpenBinaryDirect methods for CSOM for SharePoint Online

谁说胖子不能爱 提交于 2021-01-29 14:31:23
问题 Based on the doc from MS https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/using-csom-for-dotnet-standard, Save/OpenBinaryDirect methods is not available for .NET core app, they suggest to use regular file API, so what is the alternative way to read/write files stored in SharePoint online? what is the regular file API? does anyone done this? any example code/documentation? 回答1: Download file in .NET Core CSOM: using (var authenticationManager = new AuthenticationManager()) using (var

Manual decode a Bearer Token using Azure Active Directory, How do I validate?

此生再无相见时 提交于 2021-01-29 13:00:52
问题 I'm using the code below in a Net Core WebApi app and it's working well. I can decode the JWT that it produces, but I would also like to verify it's signature. But, where do I get the key to verify it with? tenant = Configuration.GetSection("AzureAD:Tenant").Value; Logger.AppLogDebug("tenat value found: [{0}]", tenant); azureAdInstance = Configuration.GetSection("AzureAD:AzureADInstance").Value; Logger.AppLogDebug("azureAdInstance value found: [{0}]", azureAdInstance); audience =

Claims Identity .NET CORE 3.0 API JWT

不打扰是莪最后的温柔 提交于 2021-01-29 10:17:05
问题 I'm trying to develop a web API on .NET CORE 3.0 but I can't get userId from the controller this is my StartUp RSAParameters keyParams = RsaKeyUtils.GetKeyParameters("jwt_key.conf"); var key = new RsaSecurityKey(keyParams); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters() { IssuerSigningKey = key, ValidAudience = GappedAuthSettings.TokenAudience, ValidIssuer = GappedAuthSettings

Security user actions in ASP.Net Core Web API

▼魔方 西西 提交于 2021-01-29 10:02:34
问题 I create project for test authentication in ASP.Net Core Web API with using JWT tokens. I implemented the basic functionality for working with accounts, but I ran into some problems. UsersController: [Authorize] [ApiController] [Route("[controller]")] public class UsersController : ControllerBase { private readonly IUserService _userService; private readonly IAuthenticationService _authenticationService; public UsersController( IUserService userService, IAuthenticationService