asp.net-core-webapi

How to use identityserver3 in asp.net core 2.0 webapi to validate token from Identityserver3 server

你说的曾经没有我的故事 提交于 2021-02-07 20:21:05
问题 I have a identityserver which is using IdentityServer3 to issue tokens. I am creating an asp.net core 2.0 api client. How to validate the token issued by Identityserver3 in ASP.Net Core 2.0 api application? I tried to install Identityserver3.AccessTokenValidation.AspNetCore, but getting error saying it is not compatible with core. Can anyone help me how to do this? Thanks 回答1: With .Net Core 2 you can use IdentityServer4.AccessTokenValidation to validate IdentityServer3 token , just make sure

How to acccept date in dd-MM-yyyy format in net core web api?

心不动则不痛 提交于 2021-02-07 20:13:46
问题 I am using net core 3.1 in my web API project. I have created one API which accepts the date from the user. By default MM-dd-yyyy format is accepted in the project. But I want to accept the date in dd-MM-yyyy format and validate all dates accordingly. Below is my api : [HttpGet] public async Task<IActionResult> Get(DateTime fromDate, DateTime toDate) { return Ok(); } Also, I have APIs in which the date parameter is passed in the request body as JSON. I have tried following StackOverflow

ASP.NET CORE Web API - delete action not firing (404 not found)

北城以北 提交于 2021-02-07 14:20:31
问题 I have a simply controller to CRUD operations. All actions works expect the last action named Delete which is HTTP DELETE action. When I try call delete action with example url: http://localhost/api/groups/1/attendances/10 then application returns 404 Not Found and action is not firing. In my other controllers delete action works correctly. One difference is that in others controllers I have one route attribute on controller instead of on each action. This is a problem? public class

How to bind a multipart/form-data file without filename to IFormFile in ASP.NET Core

让人想犯罪 __ 提交于 2021-02-07 10:11:39
问题 In a simple controller action in ASP.NET Core 3.1 that accepts multipart/form-data parameters: using System.ComponentModel.DataAnnotations; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace WebApplication { public class Controller : ControllerBase { [HttpPost("length")] public IActionResult Post([FromForm] Input input) { if (!ModelState.IsValid) return new BadRequestObjectResult(ModelState); return Ok(input.File.Length); } public class Input { [Required] public

How to bind a multipart/form-data file without filename to IFormFile in ASP.NET Core

断了今生、忘了曾经 提交于 2021-02-07 10:10:25
问题 In a simple controller action in ASP.NET Core 3.1 that accepts multipart/form-data parameters: using System.ComponentModel.DataAnnotations; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace WebApplication { public class Controller : ControllerBase { [HttpPost("length")] public IActionResult Post([FromForm] Input input) { if (!ModelState.IsValid) return new BadRequestObjectResult(ModelState); return Ok(input.File.Length); } public class Input { [Required] public

How to send email with attachment using MimeMessage in asp.net core web API?

て烟熏妆下的殇ゞ 提交于 2021-02-07 08:31:14
问题 I've tried with only simple text but i want to sent email with attachment. var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("Test","test@gmail.com")); emailMessage.To.Add(new MailboxAddress("Demo", "demo@gmail.com")); emailMessage.Subject = "Hello"; emailMessage.Body = new TextPart("html") { Text = "Hi............" }; // I want Attachment here with body text.. //Send Email. using (var client = new SmtpClient()) { await client.ConnectAsync("smtp.gmail.com", 587,

How to send email with attachment using MimeMessage in asp.net core web API?

半城伤御伤魂 提交于 2021-02-07 08:29:10
问题 I've tried with only simple text but i want to sent email with attachment. var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("Test","test@gmail.com")); emailMessage.To.Add(new MailboxAddress("Demo", "demo@gmail.com")); emailMessage.Subject = "Hello"; emailMessage.Body = new TextPart("html") { Text = "Hi............" }; // I want Attachment here with body text.. //Send Email. using (var client = new SmtpClient()) { await client.ConnectAsync("smtp.gmail.com", 587,

Odata Webapi - how to inject a ODataResourceDeserializer in 7.0 core?

Deadly 提交于 2021-02-07 08:22:35
问题 documentation is very sparce and all i tried results in the deserializer injected but normal odata url's not working anymore. https://github.com/OData/WebApi/issues/158 has solutions buut for 5.6. The final relevant comment is: @dbenzhuser - In that commit, look at ODataFormatterTests.cs for how inject a custom deserializer/deserializer provider. You can still use a custom DeserializerProvider but it's injected through DI instead of injecting it through ODataMediaTypeFormatters. which is

Odata Webapi - how to inject a ODataResourceDeserializer in 7.0 core?

情到浓时终转凉″ 提交于 2021-02-07 08:22:28
问题 documentation is very sparce and all i tried results in the deserializer injected but normal odata url's not working anymore. https://github.com/OData/WebApi/issues/158 has solutions buut for 5.6. The final relevant comment is: @dbenzhuser - In that commit, look at ODataFormatterTests.cs for how inject a custom deserializer/deserializer provider. You can still use a custom DeserializerProvider but it's injected through DI instead of injecting it through ODataMediaTypeFormatters. which is

In Swagger UI, how can I remove the padlock icon from “anonymous” methods?

﹥>﹥吖頭↗ 提交于 2021-02-07 02:49:32
问题 I'm creating an API with .Net Core 2.1 and using JSON Web Token (JWT) for authentication. I have 2 controllers: AuthenticationController and UserController . I have decorated AuthenticationController with [AllowAnonymous] and UserController with [Authorize] . Swagger is working correctly: it allows me to hit the endpoints in AuthenticationController (SignUp/SignIn) without requesting authorization, and it does request JWT to hit the endpoints in UserController . However, in Swagger UI, every