asp.net-core-webapi

IdentityServer4 usage of IdentityServerTools to create a token from within identity server

纵然是瞬间 提交于 2019-12-06 07:12:21
问题 I'm using IdentityServer4 and have a scenario where I need to initiate a call to a secured API during a password reset process. IdentityServer4 does provide IdentityServerTools for the purpose of calling a secured resource from an extensibility point, however there is currently no documentation or examples for the indented usage. How does one go about creating the necessary token using the provided methods in IdentityServerTools ? 回答1: IdentityServerTools is available from DI. Simply inject

Multiple types [FromBody] on same method .net core web api

纵饮孤独 提交于 2019-12-06 05:01:45
问题 I have a controller with one POST method, which will receive an xml string which can be of 2 types. Eg: [HttpPost("postObj")] public async Task<IActionResult> postObj([FromBody]firstClass data) { if (data != null)... I would like to be able to bind to multiple types on the same route ([HttpPost("postObj")]) So that I can receive on http://127.0.0.1:5000/api/postObj with firstClass xml in the body, or secondClass xml in the body, and act accordingly. I tried making another method with the same

Sustainsys SAML2 Sample for ASP.NET Core WebAPI without Identity

故事扮演 提交于 2019-12-06 03:41:51
Does anyone have a working sample for Sustainsys Saml2 library for ASP.NET Core WebAPI only project (no Mvc) and what's more important without ASP Identity? The sample provided on github strongly relies on MVC and SignInManager which I do not need nor want to use. I added Saml2 authentication and at first it worked fine with my IdP (I also checked the StubIdP provided by Sustainsys) for first few steps so: IdP metadata get properly loaded My API properly redirects to sign-in page Sign-in page redirects to /Saml2/Acs page, and I see in the logs that it parses the result successfully However I

Rename model in Swashbuckle 6 (Swagger) with ASP.NET Core Web API

回眸只為那壹抹淺笑 提交于 2019-12-06 02:06:16
问题 I'm using Swashbuckle 6 (Swagger) with ASP.NET Core Web API. My models have DTO as a suffix, e.g., public class TestDTO { public int Code { get; set; } public string Message { get; set; } } How do I rename it to just "Test" in the generated documentation? I've tried adding a DataContract attribute with a name, but that didn't help. [HttpGet] public IActionResult Get() { //... create List<TestDTO> return Ok(list); } 回答1: Figured it out... similar to the answer here: Swashbuckle rename Data

Host RestAPI inside IIS

青春壹個敷衍的年華 提交于 2019-12-06 02:01:39
I have a rather simple .NET WebApi application which I'm trying to host inside IIS. Followed all of the instructions from MS site about this. here is the startup method for it. public static void Main(string[] args) { var host = WebHost.CreateDefaultBuilder(args) .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .Build(); host.Run(); } I configured the Application pool to not use any managed code but I'm getting still this error in logs Application startup exception: System.InvalidOperationException: Application is running inside IIS

Determine port in asp.net core

♀尐吖头ヾ 提交于 2019-12-06 01:15:11
I want to make some microservices with asp.net core (Web Api) For service discovery I want use Consul where I must register the services via the HTTP API including IP and port. My question is: How can I know which port is used within in a service? Is there a way to determine the used port via code? Yeah, Use HttpContext.Connection.LocalPort to get the local port that the server is listening on. 来源: https://stackoverflow.com/questions/41165303/determine-port-in-asp-net-core

When using an API route, return Http Response 401 instead of redirect to login page when not authorised

眉间皱痕 提交于 2019-12-06 00:28:51
I'm building an ASP.NET Core 2.0 website using MVC and WebAPI to provide access to a series of microservices. Where a WebAPI controller requires a user to be authenticated and authorised (using the Authorize attribute), any unauthorised or not-logged in user gets the response back as the entire HTML for the MVC login page. When unauthorised users access the API, I would like to return the HTTP status code 401 and its associated error message in the response, instead of an entire HTML page. I've looked at a few existing questions and noticed that they either refer to ASP.NET MVC (such as

How to debug startup in Web Core API?

纵饮孤独 提交于 2019-12-05 23:57:38
问题 I have an MVC website that uses a Web Core API. After making a minor change and a deployment I unexpectedly got an error; Response status code does not indicate success: 500 (Internal Server Error). So I enabled the log file for the Web Core API (see https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/troubleshoot?view=aspnetcore-2.0#aspnet-core-module-stdout-log) and I get this error message; Application startup exception: System.Collections.Generic.KeyNotFoundException: The

Enum type no longer working in .Net core 3.0 FromBody request object

旧街凉风 提交于 2019-12-05 21:21:32
I have recently upgraded my web api from .Net core 2.2 to .Net core 3.0 and noticed that my requests are getting an error now when I pass an enum in a post to my endpoint. For example: I have the following model for my api endpoint: public class SendFeedbackRequest { public FeedbackType Type { get; set; } public string Message { get; set; } } Where the FeedbackType looks like so: public enum FeedbackType { Comment, Question } And this is the controller method: [HttpPost] public async Task<IActionResult> SendFeedbackAsync([FromBody]SendFeedbackRequest request) { var response = await

.Net Core web api not working after deployed to Azure

烂漫一生 提交于 2019-12-05 20:55:33
I do have a simple .Net Core web api application, the one made by Visual Studio when a new project is created. I want to deploy it to an Azure App Service via FTP (part of a TFS 2017 build job), which is successful: However, when trying a GET like http://somerandomname.azurewebsites.net/api/values all I get is a 404 with the text The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. From Kudu I get the following error: What am I missing? So a web.config is needed. The one which VS 2017 populates with some default values when a new item is added