asp.net-web-api

IActionResult vs ObjectResult vs JsonResult in ASP.NET Core API

两盒软妹~` 提交于 2021-01-18 04:10:48
问题 What's the best option to use in a Web API that will return both HTTP status codes and JSON results? I've always used IActionResult but it was always a Web App with a Web API. This time it's only Web API . I have the following simple method that's giving me an error that reads: Cannot implicitly convert type Microsoft.AspNetCore.Mvc.OkObjectResult to System.Threading.Tasks.Task Microsoft.AspNetCore.Mvc.IActionResult [HttpGet] public Task<IActionResult> Get() { return Ok(); } 回答1: Return the

ApiExplorer: How to Change The Default for IgnoreApi

≡放荡痞女 提交于 2021-01-07 02:58:27
问题 We have a couple of ApiController implementations and we do not want most operations to be included in the metadata of ApiExplorer. By default, if you do not add [ApiExplorerSettings(IgnoreApi = true)] to your operation, it will be added so this means the default is false. This probably due to IgnoreApi being a boolean and defaulting to false but how can I change this default to true without having to override ApiExplorerSettings ? This is a basic WebApi implementation without using MVC

ApiExplorer: How to Change The Default for IgnoreApi

﹥>﹥吖頭↗ 提交于 2021-01-07 02:56:52
问题 We have a couple of ApiController implementations and we do not want most operations to be included in the metadata of ApiExplorer. By default, if you do not add [ApiExplorerSettings(IgnoreApi = true)] to your operation, it will be added so this means the default is false. This probably due to IgnoreApi being a boolean and defaulting to false but how can I change this default to true without having to override ApiExplorerSettings ? This is a basic WebApi implementation without using MVC

ASP.NET Core Web API runs locally but not on Azure app service

北城余情 提交于 2021-01-05 12:00:20
问题 I have been following this link exactly (https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-2.2&tabs=visual-studio) to create my web api. **Locally, it is working fine. Tested the links and it returned JSON data However, once I deploy my web api up to azure app service, all my api links have been returning me error 404. Is there anything that I might have missed out for routing? In my controller I have added this to my head. [Route("api/xxx")] [ApiController]

REST error-The request contain entity body but no Content-Type header.The infered media type application/octet-stream is not support for this resource

主宰稳场 提交于 2021-01-04 05:47:14
问题 I'm trying to send POST request. While sending via POSTMAN all goes well, then I try to send it by C# code: ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; var client = new RestClient(MY-URL); var request = new RestRequest(Method.POST); request.Credentials = new System.Net.NetworkCredential(ServerUsername, Password); request.AddHeader("Cache-Control",

REST error-The request contain entity body but no Content-Type header.The infered media type application/octet-stream is not support for this resource

让人想犯罪 __ 提交于 2021-01-04 05:46:37
问题 I'm trying to send POST request. While sending via POSTMAN all goes well, then I try to send it by C# code: ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; var client = new RestClient(MY-URL); var request = new RestRequest(Method.POST); request.Credentials = new System.Net.NetworkCredential(ServerUsername, Password); request.AddHeader("Cache-Control",

Send messages via SignalR HubContext from method in project outside where Hubs are located

▼魔方 西西 提交于 2021-01-04 05:39:30
问题 I have a WebAPI project where the API, Service and Data layers are all in separate projects of the same solution. As part of a method in my Service project, I want to send a message to the connected clients of a hub in the API project. So far all of the examples I have found have everything in a single project and use a controller as the example sending a message via a hub. I've tried dependency injection (Autofac) however I am unable to get a reference to the MessageHub. [HubName("messages")

How to take OData Queryable Web API endpoint filter and map it from DTO object?

爷,独闯天下 提交于 2021-01-04 03:12:40
问题 I have a simple Web API endpoint which can accept incoming OData queries: public IActionResult GetProducts(ODataQueryOptions<ProductDTO> options) { var results = DomainLayer.GetProducts(options); return Ok(results); } I specifically want to be able to query against ProductDTO objects and to be able to filter or sort against the properties of the DTO representation. My design issue is that I want to take advantage of the filter parsing/applying logic of the OData library but I don't want to

How to take OData Queryable Web API endpoint filter and map it from DTO object?

跟風遠走 提交于 2021-01-04 03:07:12
问题 I have a simple Web API endpoint which can accept incoming OData queries: public IActionResult GetProducts(ODataQueryOptions<ProductDTO> options) { var results = DomainLayer.GetProducts(options); return Ok(results); } I specifically want to be able to query against ProductDTO objects and to be able to filter or sort against the properties of the DTO representation. My design issue is that I want to take advantage of the filter parsing/applying logic of the OData library but I don't want to

Automated endpoint testing protected by Azure AD B2C

旧时模样 提交于 2020-12-30 02:30:47
问题 I have a WebAPI application which authenticates users with their Azure B2C token they have acquired from signing in with their credentials. I need to write some tests against my WebAPI now but I'm not sure how I can automate acquiring a token given that I need to sign in on https://login.microsoftonline.com ... Short of using selenium or something to sign in - is there another alternative for acquiring a token to use? 回答1: I assume that you want to get token with non-interactive. I think you