asp.net-apicontroller

ASP.NET Testing Api controller: Uri(Request.GetEncodedUrl()…) returns null

帅比萌擦擦* 提交于 2021-02-19 07:43:49
问题 I am testing an ASP.NET Core Api post method, but I get a System.NullReferenceException causing my test to fail. The null exception appears when I try to return a Created()-ActionResult, like this: return Created(new Uri(Request.GetEncodedUrl() + "/" + personDto.Id), personDto); My personDto.Id nor the personDto is not null, but the result of the Uri() returns null. I have googled but not found a solution, but I believe I have to mock the Uri()-method in some way (I am new to testing and asp

Why ASP.NET MVC app doesn't recognize user role changes right after modification?

无人久伴 提交于 2021-02-19 05:52:06
问题 I have an ASP.NET MVC hybrid app which has an ApiController besides the MVC Controllers. I'm using role based authorization attributes within both the MVC Controllers and the ApiController both at the controller level and sometimes on method level. I'm using Entity Framework 6 with Model based design. The Controller level authorizations: [Authorize(Roles = "Administrator,RegularUser")] public class EngineController : ApiController { or [System.Web.Mvc.Authorize(Roles = "Administrator

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

Conventional Routing in ASP.NET Core API

大憨熊 提交于 2020-02-28 05:50:19
问题 Problem: I'm creating an API Application with NET Core 3.1. I'd like to avoid to set route attribute over every ApiControllers and Actions. I tryed a lot of combinations over UseEndpoints to set a conventional route, but i'm failing. With some configuration I can't get the Api working, with some others I get this exception during startup: InvalidOperationException: Action 'ApiIsWorking' does not have an attribute route. Action methods on controllers annotated with ApiControllerAttribute must

need route for my web api 2 controller

落爺英雄遲暮 提交于 2020-01-24 08:48:28
问题 I have a simple WebApi2 controller that returns XML but I cannot add another method properly with the routing I have defined: namespace CBMI.WebAPIservice.Controllers { public class MarkersController : ApiController { public HttpResponseMessage Get(int? id) { int i = id.HasValue ? id.Value : 0; XmlDocument docContent = GetXmlDataFromDB(i); return new HttpResponseMessage { Content = new StringContent(docContent.InnerXml.ToString(), Encoding.UTF8, "application/xml") }; } public

C# ADO: Optimize query and its performance

我与影子孤独终老i 提交于 2020-01-16 12:03:26
问题 I have a C# RestApi which need to extract information of records from database using ADO by executing queries like this: declare @id1 int set @id1 = (select id from myTable where col1= x1, col2 = y1, col3 = z1 from mappingTable) declare @id2 int set @id2 = (select id from myTable where col1= x2, col2 = y2, col3 = z2 from mappingTable) declare @id3 int set @id3 = (select id from myTable where col1= x3, col2 = y3, col3 = z3 from mappingTable) . . . declare @idN int set @idN = (select id from

how to test apiController

ぃ、小莉子 提交于 2020-01-05 15:14:50
问题 Im working on an existing Windows Service project in VS 2013. I've added a web API Controller class I cant remember now if its a (v2.1) or (v1) controller class....Anyway I've called it SynchroniseFromAwsService Im trying to call it from a AWS lambda call but it is telling me I dont have access. So I need to test it locally to see if it is working to try and diagnose the issue. I want to test this locally but am unsure how to do so..please see code... namespace Workflow { public class

Core 2.0 API Auth with JWT returns unauthorized

£可爱£侵袭症+ 提交于 2020-01-04 15:54:52
问题 I'm trying to add Token Authentication with JWT to my .Net Core 2.0 app. I have a simple controller that returns a list of users for testing. [Authorize] [Route("api/[controller]")] public class UsersController : Controller { ... [HttpGet] [Route("api/Users/GetUsers")] public IEnumerable<ApplicationUser> GetUsers() { return _userManager.Users; } } I have an API Controller for Token security. It has a login method which returns a Token string result. [HttpPost(nameof(Login))] public async Task