asp.net-core-webapi

Using ZipArchive with ASP.NET Core Web Api

*爱你&永不变心* 提交于 2019-12-24 02:37:10
问题 The question is how can I create a zipped (compressed) folder on the fly using ASP.NET Core 2 (currently) Web API? I am using System.IO.Compression.ZipArchive I have been several blog posts where this is done using streams or byte arrays, all give me the same output. I am able to download the zip folder but unable to open it. The zipped folder is the correct size. Even though it doesn't open. They way I want it to work is for a user to click a button which runs this action and return a zipped

How to correctly setup Policy Authorization for WEB API in .NET Core

让人想犯罪 __ 提交于 2019-12-23 23:01:49
问题 I have this Web API project, with no UI. My appsettings.json file has a section listing tokens and which client they belong to. So the client will need to just present a matching token in the header. If no token is presented or an invalid one, then it should be returning a 401. In ConfigureServices I setup authorization .AddTransient<IAuthorizationRequirement, ClientTokenRequirement>() .AddAuthorization(opts => opts.AddPolicy(SecurityTokenPolicy, policy => { var sp = services

.Net Core WebAPI connection reset, when I have “include” in my controller

大城市里の小女人 提交于 2019-12-23 16:12:45
问题 I have a new project with .Net Core. It's a WebAPI project. And I have a separate project for my model. In WebAPI project, in a controller, I have something like this: // GET: api/questions [HttpGet] public IEnumerable<Question> GetQuestions() { return _context.Questions .Include( i => i.QuestionType ); } When I call http://localhost:55555/api/questios/ it just returns the first record, and then this error message: Recv failure: Connection was reset If I remove the Include part and just

Angular 2 AspNetCore WebApi CORS issue: Response for preflight has invalid HTTP status code 401

穿精又带淫゛_ 提交于 2019-12-23 15:44:18
问题 I am attempting to implement simple token based authentication in an Angular 2 RC6 application against an AspNetCore WebApi project that I've implemented in Visual Studio 2015. I have put my sample application on github at: https://github.com/tonywr71/Snazzle which is a fully functioning application. In the application, I click on the Login menu item, put in login and password information then click login. It successfully returns am authentication token, which I store in isolated storage. I

WebAPI & IdentityServer on ASP.NET Core Project

血红的双手。 提交于 2019-12-23 15:16:44
问题 I have an ASP.NET Core project which is hosted on Azure and has many registered users. I want to create a mobile app and I need an API which provides access to same users accounts and Identity system. I found out that IdentityServer can help but I still don't understand how to use identityserver with WebAPI in the same project as I want to create a new project for webapi and allow the mobile client to authenticate using the same credentials stored in the database. Thank you :) 回答1: In this

.net core 2.2 & Angular 7: IFormFile in file upload controller is always null

蹲街弑〆低调 提交于 2019-12-23 12:48:03
问题 When looking at other answers and some google, everything seems to be fine, yet my controller never receives any data. Api uris and such are correct, the request arrives at the correct controller Angular snippet: component.html - my input field <div class="input-group"> <input type="file" #fileInput id="fileInput" (change)="stageFile()" accept="csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"> <div class="input-group-append"> <button class="btn

JWT Authentication and Swagger with .Net core 3.0

狂风中的少年 提交于 2019-12-23 11:59:27
问题 I am developing some Web Api with .Net core 3.0 and want to integrate it with SwashBuckle.Swagger. It is working fine, but when I add JWT authentication, it does not work as I expect. To do that, I added the code below: services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "My Web API", Version = "v1" }); c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Description = "JWT Authorization header using the Bearer scheme. Example: \

Override AuthorizeAttribute in ASP.Net Core and respond Json status

对着背影说爱祢 提交于 2019-12-23 10:05:03
问题 I'm moving from ASP.Net Framework to ASP.Net Core. In ASP.Net Framework with Web API 2 project, I can customize AuthorizeAttribute like this : public class ApiAuthorizeAttribute : AuthorizationFilterAttribute { #region Methods /// <summary> /// Override authorization event to do custom authorization. /// </summary> /// <param name="httpActionContext"></param> public override void OnAuthorization(HttpActionContext httpActionContext) { // Retrieve email and password. var accountEmail =

Debugging Swashbuckle Error - Failed to load API Definition

北城余情 提交于 2019-12-23 09:22:15
问题 Is there any way to get a stack trace or inner exceptions on Swashbuckle/Swagger errors? At some point, it stopped working. I'm not sure if it was when I upgraded from .Net Core 2.0 to 2.1, but I'm pretty sure it was still working after that. When I navigate to myapidomain/swagger/index.html I get this error: Which is not very helpful. It was working 2 or so weeks ago... I didn't change any Swagger configuration. It's the same as it's always been: public void ConfigureServices

Modelbinding JSON in .Net Core 2.2 Web API

我们两清 提交于 2019-12-23 09:15:56
问题 I just wasted a lot of hours with trying to get a custom ComplexTypeModelBinder to work. Whatever I did, it never worked. As it turns out, this only works when the data is POSTed as form data; when you post a JSON object (in my case from a Swagger "try out" form) the ComplexTypeModelBinder never invokes the SetProperty method. I have a lot of models, some more complex than others, and I have annotated some of the properties with a custom attribute. Whenever that property is bound I want it to