asp.net-core-2.0

Views not being copied when publish the project in netcore 2.0 visual studio 2017

允我心安 提交于 2019-12-04 20:06:30
问题 I have createa a ASP.NET Core 2.0 project in VS 2017. When I publish my project the Views folder are not there but the wwwroot folder is. This I can setup in my .csproj file with the following: <ItemGroup> <Content Update="appsettings.json;web.config" CopyToOutputDirectory="PreserveNewest"/> <Content Update="Views\**\*" CopyToOutputDirectory="PreserveNewest" /> <Content Update="wwwroot\**\*" CopyToOutputDirectory="PreserveNewest" /> </ItemGroup> but didn't work. 回答1: ASP.NET Core MVC has a

How to unique identify each request in a ASP.NET Core 2 application (for logging)

人走茶凉 提交于 2019-12-04 18:41:36
问题 In a ASP.NET Core 2 application, I need a unique identifier (e.g. Guid) for each request so I can include that id in each log and understand the sequence of logs of each request. This is not hard to write it myself, but I wonder if there is a builtin feature that I can use or a ASP.NET Core 2 way of achieving this. 回答1: You may use System.Diagnostics.Activity class (source). From Activity User Guide Activity.Id serves as hierarchical Request-Id in terms of HTTP Correlation Protocol This is

What is analog for HttpListener in .NET Core

无人久伴 提交于 2019-12-04 18:19:02
问题 I'm porting application from .NET 4 to .NET Core and can't find analog for HttpListener class Error CS0246 The type or namespace name 'HttpListener' could not be found (are you missing a using directive or an assembly reference?) Update1 private readonly HttpListener _httpListener; if (!HttpListener.IsSupported) { throw new NotSupportedException( "The Http Server cannot run on this operating system."); } _httpListener = new HttpListener(); _httpListener.Prefixes.Add(prefix); _sessionSettings

Reducing Identity cookie size in .NET Core 2.0?

99封情书 提交于 2019-12-04 17:29:51
so here's my situation: I have a .NET Core 2.0 web app which using Identity and Google auth. Claims retrieved from Google login are email, first name, last name, and domain. Here's where I run in to some trouble. I also use the Google Directory service to obtain the user's email groups. These groups are used as roles for authorization within the app which get stored as claims, thus making the Identity cookie larger. When someone has a ton of Google Groups, the cookie actually ends up being too big and gives the user a 502.3 error on our websites. Is there any way to reduce the size of the

.NET Core 2.0 Cookie Events OnRedirectToLogin

感情迁移 提交于 2019-12-04 14:28:24
问题 How can I apply a middleware to the OnRedirectToLogin event in Cookie options (so i can use dependency injection), OR how can I retrieve actionContext from RedirectContext? I have tried searching for documentation or examples, but it is hard to find, and I have not seen any examples explaining or defining how. Is this even possible? my Startup.cs services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(o => { o.AccessDeniedPath = new PathString("/Error

How to Write xUnit Test for .net core 2.0 Service that uses AutoMapper and Dependency Injection? [closed]

て烟熏妆下的殇ゞ 提交于 2019-12-04 13:48:56
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I'm new to .net core/C# programming (coming over from Java) I have the following Service class the that uses dependency injection to get an AutoMapper object and a data repository object for use in creating a collection of SubmissionCategoryViewModel objects: public class SubmissionCategoryService :

Can't use registered singetons in ConfigureServices without them being instantiated twice

人走茶凉 提交于 2019-12-04 13:24:20
I have a .Net Core project that registers a number of Singletons as follows: public void ConfigureServices(IServiceCollection services) { services.AddMemoryCache(); services.AddLogging(); services.AddSingleton<IConfiguration>(Configuration); services.AddSingleton<IDbFactory, DefaultDbFactory>(); services.AddSingleton<IUserRepository, UserRepository>(); services.AddSingleton<IEmailService, EmailService>(); services.AddSingleton<IHostedService, BackgroundService>(); services.AddSingleton<ISettingsRepository, SettingsRepository>(); services.AddSingleton(typeof(TokenManager)); var sp = services

Is Microsoft.Azure.NotificationHubs 1.0.9 compatible with .NET Core 2.0?

风流意气都作罢 提交于 2019-12-04 13:10:36
We are using NotificationHubs version 1.0.9 with .NetCore 2.0 and .Net Framework 4.7. At compile time, we get this warning: "Package Microsoft.Azure.NOtificationHubs 1.0.9 was restored using '.NETFramework, version=4.6.1' instead of the project target framework '.NETCoreApp, version=2.0. this package may not be fully compatible with your project." Everything is still built, but at runtime when this call is invoked: RegistrationDescription hubRegistration = await hubClient.CreateAppleNativeRegistrationAsync(device.DeviceToken); //hubClient is NotificationHubClient We get this error: Has anyone

test .net core 2 page using Postman return 400 bad request

余生颓废 提交于 2019-12-04 12:11:06
I created default project template of .net core 2 pages , than I'm trying to test a call to a page OnPostAsync (not api controller) using postman , but I always get 400 bad request , tried to play with headers etc` but with no success , any 1 manage to do this? After this will work ,my goal is to do do end-to-end/load tests thanks! answer was found https://github.com/aspnet/Mvc/issues/7012 which it's a workaround to disable IgnoreAntiforgeryToken using [IgnoreAntiforgeryToken(Order = 1001)] on PageModel 来源: https://stackoverflow.com/questions/47453401/test-net-core-2-page-using-postman-return

Unable to Retrieve Claims in .NET Core 2.0

怎甘沉沦 提交于 2019-12-04 11:28:45
问题 I am using an OpenId Connect Authentication Server , specifically Identity Server 4 (version 1.5.2) on .NET Core 1.1. I have this running with ASP.NET Framework MVC 5 and ASP.NET Core 1.1 MVC web applications. The following configuration is from a .NET Core 1.1 web application: public void Configure( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { app.UseDeveloperExceptionPage(); app.UseStatusCodePages(); app.UseRewriter(new RewriteOptions()