asp.net-core-1.0

Optionally override request culture via url/route in an ASP.NET Core 1.0 Application

与世无争的帅哥 提交于 2019-11-29 01:33:41
问题 I am trying to override the culture of the current request. I got it working partly using a custom ActionFilterAttribute . public sealed class LanguageActionFilter : ActionFilterAttribute { private readonly ILogger logger; private readonly IOptions<RequestLocalizationOptions> localizationOptions; public LanguageActionFilter(ILoggerFactory loggerFactory, IOptions<RequestLocalizationOptions> options) { if (loggerFactory == null) throw new ArgumentNullException(nameof(loggerFactory)); if

How to use SqlServer.Types / spatial types within ASP.NET Core 1.0 application

谁都会走 提交于 2019-11-29 01:04:01
问题 One of our class libraries uses the Microsoft spatial types like DbGeography. When running our application on a clean machine without older versions of SQL Server and Visual Studio, we get this exception: Spatial types and functions are not available for this provider because the assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be found. The solution is apparently to install this nuget package: Install-Package Microsoft.SqlServer.Types After installing, the nuget package

How to get “Manage User Secrets” in a .NET Core console-application?

女生的网名这么多〃 提交于 2019-11-29 00:20:40
问题 When I create a new ASP .NET Core Web -Application, I can right-click the project in Visual Studio, and I see a context-menu entry called "Manage User Secrets". When I create a new .NET Core Console -Application, I don't see this context-menu entry. However, a "Web"-Application shows as "console" application in the project settings. Is there any way I can get this context-menu entry in a console-application ? 回答1: "Manage user secrets" from a right click is only available in web projects.

How to publish environment specific appsettings in .Net core app?

对着背影说爱祢 提交于 2019-11-28 22:45:47
I have 3 environment specific appsettings files in my .Net core application in project.json I have setup publishOptions like this. ( based on suggestion here ) "publishOptions": { "include": [ "wwwroot", "appsettings.development.json", "appsettings.staging.json", "appsettings.production.json", "web.config" ] }, I have 3 corresponding startup classes that uses appropriate appsettings based on environment var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: false, reloadOnChange: true); However when I publish

Entity Framework Core 1.0 unit of work with Asp.Net Core middleware or Mvc filter

孤者浪人 提交于 2019-11-28 21:27:31
I am using EF Core 1.0 (previously known ad EF7) and ASP.NET Core 1.0 (previously known as ASP.NET 5) for a RESTful API. I'd like to have some unit of work scoped to an http request in such a way that when responding to the HTTP request either ALL the changes made to the DbContext will be saved onto the database, or none will be saved (if there was some exception, for example). In the past I have used WebAPI2 for this purpose with NHibernate by using an Action filter where I begin the transaction on action executing, and on action executed I end the transaction and close the session. This was

How to set .NET Core in #if statement for compilation

拜拜、爱过 提交于 2019-11-28 20:59:57
问题 I created a multi targeted framework project. I use something like this : #if NET40 Console.WriteLine("hello from net 4"); #endif But I cant find wildcard for .NET Core. I tried : #if NETCOREAPP1.0 Console.WriteLine("hello from net Core"); #endif but it is not valid statement. Thanks. 回答1: You need underscore _ instead of point : NETCOREAPP1_0 or the more recent NETCOREAPP1_1 and NETCOREAPP2_0 The article https://docs.microsoft.com/en-us/dotnet/articles/core/tutorials/libraries includes a

Using DataTable in .NET Core

一曲冷凌霜 提交于 2019-11-28 20:49:57
I have a stored procedure in SQL Server that accepts a User-Defined Table Type. I'm following the answer from this post Bulk insert from C# list into SQL Server into multiple tables with foreign key constaints on how to send a DataTable to a stored procedure in SQL. But when I create DataTable table = new DataTable(); I get an error that DataTable does not contain a constructor that takes 0 arguments . I found this https://github.com/VahidN/EPPlus.Core/issues/4 which basically saying DataTable is no longer supported in .NET Core. So now what? how do I create a DataTable (or what is it's

How to get current url in view in asp.net core 1.0

僤鯓⒐⒋嵵緔 提交于 2019-11-28 19:59:32
In previous versions of asp.net, we could use @Request.Url.AbsoluteUri But it seems it's changed. How can we do that in asp.net core 1.0? You have to get the host and path separately. @Context.Request.Host@Context.Request.Path You need scheme, host, path and queryString @string.Format("{0}://{1}{2}{3}", Context.Request.Scheme, Context.Request.Host, Context.Request.Path, Context.Request.QueryString) or using new C#6 feature "String interpolation" @($"{Context.Request.Scheme}://{Context.Request.Host}{Context.Request.Path}{Context.Request.QueryString}") You can use the extension method of Request

ASPNET Core Server Sent Events / Response flush

。_饼干妹妹 提交于 2019-11-28 16:32:42
问题 While there is no official documentation, does anyone know how SSE may be implemented using ASP.NET Core? I suspect one implementation may use custom middleware, but maybe it is possible to do that in controller action? 回答1: wwwroot/index.html On page load, create an EventSource for the http://www.somehost.ca/sse url. Then write its events to the console. <body> <script type="text/javascript"> var source = new EventSource('sse'); source.onmessage = function (event) { console.log('onmessage: '

ADO.NET entity data model (.edmx) in ASP.NET MVC core 1.0

半世苍凉 提交于 2019-11-28 13:13:35
I have couple of questions regarding how to use ADO.NET entity data model (.edmx) in ASP.NET MVC core 1.0 application- As we are migrating application from MVC 5 to MVC core 1.0, how do we migrate .edmx from MVC5 application developed in VS2013 to MVC core 1.0 new VS2015? How do I create new ADO.NET entity data model (.edmx) using Database First approach in MVC core 1.0 application in VS2015? [I have already tried creating POCO model and then use scaffold migration command, but want to understand using old wizard approach] ADO.NET entity data model (.edmx) is not supported in Entity Framework