asp.net-core-2.0

ASP.NET Core Authorization: Combining OR requirements

為{幸葍}努か 提交于 2020-01-24 20:01:07
问题 I'm not sure how to implement combined "OR" requirements in ASP.NET Core Authorization. In previous versions of ASP.NET this would have been done with roles, but I'm trying to do this with claims, partly to understand it better. Users have an enum called AccountType that will provide different levels of access to controllers/actions/etc. There are three levels of types, call them User, BiggerUser, and BiggestUser. So BiggestUser has access to everything the account types below them have and

Does injecting ILogger<T> create a new logger each time?

杀马特。学长 韩版系。学妹 提交于 2020-01-24 04:54:05
问题 On the logging samples in the documentation, there is an example how to inject a logger into a controller: public class TodoController : Controller { private readonly ITodoRepository _todoRepository; private readonly ILogger _logger; public TodoController(ITodoRepository todoRepository, ILogger<TodoController> logger) { _todoRepository = todoRepository; _logger = logger; } } Does the DI framework create a new logger each time I inject a logger into something like here? Is there a better way?

Create docx word document web api .net core 2.0

折月煮酒 提交于 2020-01-24 04:09:05
问题 I am developing a Web API project in Asp.net core 2.0. I am in need of a library or way to create Word document. I have searched an tried NPOI and DocX. Both are not as good as expected. Can anyone suggest me a tool? 回答1: At first glance, the below link can help somehow: https://asp.net-hacker.rocks/2017/02/23/word-document-formatter-in-aspnetcore.html Anyway, about DOCX - Word Document using Open XML SDK by Microsoft - you can install Open XML SDK into your solution using the version 2.8.1.

Error CS1061 'IdentityBuilder' does not contain a definition for 'AddEntityFrameworkStores'

你说的曾经没有我的故事 提交于 2020-01-23 06:08:26
问题 I'm trying to change the primary key in ASPNET Core 2.0 to Guid or long . I've tried the following examples in both these links Link1 and Link2 However, in the Startup class I get the following error Error CS1061 'IdentityBuilder' does not contain a definition for 'AddEntityFrameworkStores' and no extension method 'AddEntityFrameworkStores' accepting a first argument of type 'IdentityBuilder' could be found (are you missing a using directive or an assembly reference?) I think the reason is

Default proxy in .net core 2.0

前提是你 提交于 2020-01-23 04:30:26
问题 I saw couple of questions asked about core 2.0 on how to make HttpClient to use default proxy configured on the system. But no where found right answer. Posting this question hoping someone who might have encountered this issue might have found the solution by now. In .net framework versions I've used the following configuration in my web.config and it worked for me. <system.net> <defaultProxy useDefaultCredentials="true"></defaultProxy> </system.net> But in .net core 2.0 where I've make a

Authentication flow for Angular application for users in Azure AD

人盡茶涼 提交于 2020-01-22 02:27:46
问题 I have an Angular application which talks to several WEB API's to provide an interacted UI. I am finding really hard time in finding a way to. I am following this article which explains the Angular part of it. I am able to get the token at client side. How can my dot net core web API validate the token if the client sends this id token? 回答1: You can use JwtBearer middleware which enables an application to receive an OpenID Connect bearer token. In this document it provides code sample . Or

How to send an HTTP 4xx-5xx response with CORS headers in an ASPNET.Core web app?

牧云@^-^@ 提交于 2020-01-21 07:38:05
问题 I have a standard ASP.NET Core 2 Web App acting as a REST/WebApi. For one of my endpoints I return an HTTP 400 when the user provides bad search/filter querystring arguments. Works great with POSTMAN. But when I try and test this with my SPA app (which in effect is now crossing domains and thus doing a CORS request), I get a failure in Chrome. When doing a CORS request to an endpoint that returns an HTTP 200 response, all works fine. It looks like my error handling is NOT taking into

Httpclient This instance has already started one or more requests. Properties can only be modified before sending the first request

无人久伴 提交于 2020-01-21 04:17:07
问题 I am creating an application in .Net Core 2.1 and I am using http client for web requests. The issue is I have to send parallel calls to save time and for that I am using Task.WhenAll() method but when I hit this method I get the error "This instance has already started one or more requests. Properties can only be modified before sending the first request" Previously I was using RestSharp and everything was fine but I want to use httpclient. Here is the code: public async Task<User> AddUser

How To Disable Https in Visual Studio 2017 Web Proj ASP.NET Core 2.0

心已入冬 提交于 2020-01-20 20:14:16
问题 I've created a default project in Visual Studio 2017 with ASP.NET Core 2.0. I've chosen the Web App with MVC and with Individual Use Auth. By default, it is coming up configured and working with https. I've tried disabling that by going into project properties and removing the user ssl and changing https to http but then I get either and IIS Express Connection error or a 404. I've not see default https before. Where is that coming from and where can I disable it? 回答1: I've just created a

Controller scaffolding doesn't work in VS 2017 preview for ASP.NET Core 2 Preview

感情迁移 提交于 2020-01-17 14:47:52
问题 I'm trying to use scaffolding to generate MVC Controller with views, using Entity Framework: I created ApplicationDBContext: public class ApplicationDbContext : DbContext { public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { } public DbSet<med1.Models.House> House { get; set; } } and added to ConfigureServices: services.AddDbContext<Data.ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); And