asp.net-core-webapi

How to properly integrate OData with ASP.net Core

折月煮酒 提交于 2019-12-04 09:56:14
问题 I'm trying to create a new ASP.NET Core project with a "simple" web api using OData and EntityFramework. I have previously used OData with older versions of ASP.NET. I have set up a controller with only a simple get function. I've managed to get it working with basic OData commands as filter and top, but I can't get the expand command working. I think it's because I can't quite figure out how to set it up in Startup.cs. I have tried a lot of things including following some odata samples from

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

梦想与她 提交于 2019-12-04 06:59:45
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); } ultravelocity Figured it out... similar to the answer here: Swashbuckle rename Data Type in Model The only difference was the property is now called CustomSchemaIds instead of

Custom authorization attribute in .NET Core [duplicate]

自古美人都是妖i 提交于 2019-12-04 06:05:46
This question already has answers here : Closed 2 years ago . How do you create a custom AuthorizeAttribute in ASP.NET Core? (7 answers) I'm building an API in .NET Core 1.1. I build a custom User object from HttpContext.User in a base controller that all of my other controllers inherit from, and I have authentication enabled by default (must be manually disabled with [AllowAnonymous] when necessary). The User object has an IsAdmin property. Right now I'm checking if the user is an admin at the top of each relevant function like below, but I feel like there must be a way to add a custom

How to debug startup in Web Core API?

巧了我就是萌 提交于 2019-12-04 04:25:11
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 given key was not present in the dictionary. at System.Collections.Generic.Dictionary2.get_Item(TKey key)

.NET Core 2 and SwashBuckle Swagger UI is not Displaying

谁说我不能喝 提交于 2019-12-04 03:36:16
I have followed a few tutorials and have gotten this to work at work but for some reason I am not able to get the UI to display but the Swagger Json is created. Last tutorial I looked at is here . My setup is like so: Nuget Package: Swashbuckle.AspNetCore(1.0.0) ConfigureServices Method: services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new Info { Title = "MediatR Example", Version = "v1", Description = "Trying out the MediatR library to simplify Request and Response logic.", TermsOfService = "WTFPL", Contact = new Contact { Email = "", Name = "", Url = "https://github.com

Set dummy IP address in integration test with Asp.Net Core TestServer

独自空忆成欢 提交于 2019-12-04 02:52:40
问题 I have a C# Asp.Net Core (1.x) project, implementing a web REST API, and its related integration test project, where before any test there's a setup similar to: // ... IWebHostBuilder webHostBuilder = GetWebHostBuilderSimilarToRealOne() .UseStartup<MyTestStartup>(); TestServer server = new TestServer(webHostBuilder); server.BaseAddress = new Uri("http://localhost:5000"); HttpClient client = server.CreateClient(); // ... During tests, the client is used to send HTTP requests to web API (the

Visual Studio keeps adding IIS Express back into my launchsettings.json

我们两清 提交于 2019-12-04 00:51:10
I am trying to remove the IIS Express profile from my .NET Core launch settings but every time i repoen the solution, Visual Studio adds it back in again. For example, in a new project my launch settings looks like this { "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:55735/", "sslPort": 0 } }, "profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "MyProject": { "commandName": "Project", "launchUrl": "http:/

Equivalent of HttpResponseException/IHttpActionResponse for .net Core webapi 2 (not mvc)

时光怂恿深爱的人放手 提交于 2019-12-03 23:44:28
When I am reading about webapi for responding to requests and handling errors everything is based around: IHttpActionResult HttpResponseException But when you create a .net core webapi project these are not available. I can find IActionResult, which seems to be the equivalent? But I'm going round in circles trying to find out a really very simple thing, which is how to handle errors in a .net core webapi because HttpResponseException is not available. I get the impression everything with 'http' in it, is just for a full MVC application. All I want to do is return an error, surely it must be

Route Name for HttpGet attribute Name for base generic controller class in asp.net core 2

人走茶凉 提交于 2019-12-03 23:34:57
I have a generic controller, which have several derived controller classes. but I cannot figure out how to handle the HttpGet's route name since it require constant. [HttpGet("{id}", Name ="should not hard coded here for derived class")] public virtual async Task<IActionResult> Get(int id) I need the route name because in my HttpPost function I want to return CreatedAtRoute() which require HttpGet's route name The route name cannot be hard coded because all the derived class need to have a different route name. here is the base controller public abstract class BaseController<TEntity, TContext>

How to validate AWS Cognito JWT in .NET Core Web API using .AddJwtBearer()

瘦欲@ 提交于 2019-12-03 16:35:35
I was having some trouble figuring out how to go about validating a JWT given to the client by AWS Cognito inside my .NET Core Web API. Not only could I not figure out what the variables for Microsoft.IdentityModel.Tokens.TokenValidationParameters were supposed to be, but once I finally did, I didn't know how to retrieve the JWT key set from https://cognito-idp.{region}.amazonaws.com/{pool ID}/.well-known/jwks.json Finally, though a lot of random Googling and trial and error, I found a (seemingly-not-very-efficient solution) solution. However, I spent way too much time doing it. Citing that,