asp.net-core-webapi

415 Unsupported Media Type asp.net core

假如想象 提交于 2021-02-16 15:48:27
问题 Detail I am trying to post a file from Postman to the endpoint I have created. but it gives me this error. I am not passing the header Content-Type in postman 415 Unsupported Media Type API [Consumes("multipart/form-data")] [HttpPost] public async Task<IActionResult> SendEmail([FromBody]Entity entity) { try { return OK(); } catch (Exception e) { throw e; } } Class public class Entity { public List<IFormFile> Files { get; set; } } 回答1: Try using [FromForm] instead of [FromBody] for the method

415 Unsupported Media Type asp.net core

混江龙づ霸主 提交于 2021-02-16 15:48:08
问题 Detail I am trying to post a file from Postman to the endpoint I have created. but it gives me this error. I am not passing the header Content-Type in postman 415 Unsupported Media Type API [Consumes("multipart/form-data")] [HttpPost] public async Task<IActionResult> SendEmail([FromBody]Entity entity) { try { return OK(); } catch (Exception e) { throw e; } } Class public class Entity { public List<IFormFile> Files { get; set; } } 回答1: Try using [FromForm] instead of [FromBody] for the method

Angular app running on azure app service not receive .AspNetCore.Antiforgery cookie sent by .net core web api app on azure

荒凉一梦 提交于 2021-02-11 08:00:36
问题 I have angular 5 app and .net core 2.0 web api app hosted on azure as app services. Apps have two urls as below. angularclient.azurewebsites.net serviceapi.azurewebsites.net The issue I am facing is angular app not receiving .AspNetCore.Antiforgery cookie that is sent by serviceapi. Http post request generated by angular app has "withCredentials: true" header. I have defined cors policy in service API as below. app.UseCors(builder => builder.WithOrigins("angularclient.azurewebsites.net")

Security token from TokenValidatedContext from the OnTokenValidated event listener is missing last string segment

那年仲夏 提交于 2021-02-10 07:48:17
问题 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. First of all this is how I generate a new token public string GenerateToken(Dictionary<string, object> payload) { DateTime tokenExpiresAt = DateTime.Now.AddMilliseconds(1); // from config byte[] symmetricKey = Convert.FromBase64String("secret"); // from config SymmetricSecurityKey symmetricSecurityKey = new

.NET 5.0 Web API won't work with record featuring required properties

不问归期 提交于 2021-02-10 07:12:59
问题 I'm using a C# 9.0 record type as a binding model for a .NET 5.0 Web API project. Some of the properties are required. I'm using the record positional syntax, but am receiving errors. public record Mail( System.Guid? Id, [property: Required] string From, [property: Required] string[] Tos, [property: Required] string Subject, string[]? Ccs, string[]? Bccs, [property: Required] Content[] Contents, Attachment[]? Attachments ); This is then exposed as the binding model for my Index action: public

.NET 5.0 Web API won't work with record featuring required properties

妖精的绣舞 提交于 2021-02-10 07:10:57
问题 I'm using a C# 9.0 record type as a binding model for a .NET 5.0 Web API project. Some of the properties are required. I'm using the record positional syntax, but am receiving errors. public record Mail( System.Guid? Id, [property: Required] string From, [property: Required] string[] Tos, [property: Required] string Subject, string[]? Ccs, string[]? Bccs, [property: Required] Content[] Contents, Attachment[]? Attachments ); This is then exposed as the binding model for my Index action: public

OData Containment

那年仲夏 提交于 2021-02-10 05:13:33
问题 I just learn that with the [Contained] attribute I can define a contained collection. This means the collection is no more accessible from my root oData system. Ok fine, but here is my model: I have a user that have addresses The user has invoices Each invoice can have one or two addresses from the user. On which collection should I add the contained attribute? 回答1: The answer to this completely depends on your domain model. The advice I would give is to use OData containment sparingly. It

OData Containment

二次信任 提交于 2021-02-10 05:12:43
问题 I just learn that with the [Contained] attribute I can define a contained collection. This means the collection is no more accessible from my root oData system. Ok fine, but here is my model: I have a user that have addresses The user has invoices Each invoice can have one or two addresses from the user. On which collection should I add the contained attribute? 回答1: The answer to this completely depends on your domain model. The advice I would give is to use OData containment sparingly. It

run additional logic besides [Authorize] annotation

不想你离开。 提交于 2021-02-10 00:34:54
问题 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:14:30
问题 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