asp.net-core-2.0

What is difference between View and Page in Asp.net core 2?

匆匆过客 提交于 2019-12-07 02:15:13
问题 I am new in Asp.net core 2. One of the new things in Asp.net core 2 are pages. But I can't figure it out What is difference between page and view? What are the benefits of pages versus views? In what cases should the page be used? Can I use both at the same time? 回答1: Really, your question is what's the difference between a Razor Page and traditional MVC. Both utilize Razor views. A Razor Page is self-contained (sort of). It has a code-behind like a Web Form, so technically you'd have a

Determine port Kestrel binded to

偶尔善良 提交于 2019-12-07 01:50:49
问题 I'm writing a simple ASP.NET Core service using ASP.NET Core empty ( web ) template. By default, it binds to port 5000 but I would like it to bind to a random available port on the system. I can do so by modifying BuildWebHost to: public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseUrls("http://*:0") // This enables binding to random port .Build(); It binds to a random port but how do I determine from within the application which

Why does Scoped service resolve as two different instances for same request?

守給你的承諾、 提交于 2019-12-06 22:08:28
问题 I have a simple service that contains a List<Foo> . In Startup.cs, I am using the services.addScoped<Foo, Foo>() method. I am inject the service instance in two different places (controller and middleware), and for a single request, I would expect to get the same instance. However, this does not appear to be happening. Even though I am adding a Foo to the List in the Controller Action, the Foo list in the Middleware is always empty. Why is this? I have tried changing the service registration

Re-target .NET Core to net471, net 472

主宰稳场 提交于 2019-12-06 21:40:26
问题 My .Netcore 2.0 project can target net471 . But when I upgraded to .NET 2.1, I can't retarget net471 or net472 Can I retarget in the latest version of .the NET core? Severity Code Description Project File Line Suppression State Error NU1202 Package Microsoft.AspNetCore.App 2.1.0 is not compatible with net471 (.NETFramework,Version=v4.7.1). Package Microsoft.AspNetCore.App 2.1.0 supports: netcoreapp2.1 (.NETCoreApp,Version=v2.1) and Severity Code Description Project File Line Suppression State

The name WebHost does not exists in current context

不问归期 提交于 2019-12-06 17:49:53
问题 I'm migrating from ASP.NET Core 1.x to v2.0 with the help of following post on docs.microsoft: https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/ I'm almost done with all the changes mentioned in that post. But there is one error that is causing troubles. Here is my Program.cs file: using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Configuration; namespace MeridiaCoreAPI { public class Program { public static void Main(string[]

Reducing Identity cookie size in .NET Core 2.0?

左心房为你撑大大i 提交于 2019-12-06 11:47:27
问题 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

Getting “Could not resolve a service of type ..” after upgrading to Core 2 Preview 2

元气小坏坏 提交于 2019-12-06 10:39:11
I've just upgraded to ASP.NET Core 2 Preview 2 and ran into a problem with the depedency injection. I get Could not resolve a service of type 'LC.Tools.API.Data.GenericDbContext' for the parameter 'context' of method 'Configure' on type 'LC.Tools.API.Startup' when running the project. I didn't have this problem when using the old version. DbContext (GenericDbContext): namespace LC.Tools.API.Data { public class GenericDbContext : DbContext { public GenericDbContext(DbContextOptions<GenericDbContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { /

How to set default datetime format for .net core 2.0 webapi

流过昼夜 提交于 2019-12-06 08:34:27
Currently in my local. The API is expecting the same formart as in SQL Server database which is yyyy-mm-dd. However when i am deploying the application into production server. The API is expecting the datetime format as yyyy-dd-mm. Is there any way to configure my .net core web api to accept yyyy-mm-dd as default format in every enviroment? 100% of the time, If I am using DateTime , I create an interface for it. It just makes life a lot easier when it's time for testing. I believe this would work for you as well. There's a couple of reasons for this method. It's testable. It abstracts the

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

扶醉桌前 提交于 2019-12-06 08:22:10
问题 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! 回答1: answer was found https://github.com/aspnet/Mvc/issues/7012 which it's a workaround to disable IgnoreAntiforgeryToken using [IgnoreAntiforgeryToken(Order =

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

不羁的心 提交于 2019-12-06 07:18:23
问题 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