asp.net-core-1.0

Using DataTable in .NET Core

放肆的年华 提交于 2019-11-27 20:46:16
问题 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

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

扶醉桌前 提交于 2019-11-27 20:26:40
问题 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? 回答1: You have to get the host and path separately. @Context.Request.Host@Context.Request.Path 回答2: 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}://

ASP.NET Core RC2 SignalR Hub Context outside request thread

删除回忆录丶 提交于 2019-11-27 19:30:25
I am currently trying out the RC2 release of ASP.NET Core and I am running into an issue with SignalR . I need to be able to send messages to the client outside of the request thread. Now in the full .NET framework you can do this like: var context = GlobalHost.ConnectionManager.GetHubContext<MyHub>(); context.Clients.<SendMessage>() But in ASP.NET Core there is no GlobalHost . I found a similar question: How to get SignalR Hub Context in a vNext Project? Where the second answer provides a method to get the hubcontext outside the request thread, but this also does not work in ASP.NET Core . So

AWS Elastic Beanstalk environment variables in ASP.NET Core 1.0

给你一囗甜甜゛ 提交于 2019-11-27 18:45:41
How do I get environment variables from elastic beanstalk into an asp.net core mvc application? I have added a .ebextensions folder with app.config file in it with the following: option_settings: - option_name: HelloWorld value: placeholder - option_name: ASPNETCORE_ENVIRONMENT value: placeholder The .ebextensions folder is included in the publish package. On deployment, both the variables are visible in the aws elasticbeanstalk console at Configuration > Software Configuration > Environment Variables However, when I try to read the variables in the application, none of the below options are

Can not find runtime target for framework .NETCoreApp=v1 compatible with one of the target runtimes for some projects

我们两清 提交于 2019-11-27 17:53:35
问题 I have a solution with many .NET Core projects. I did NuGet updates to all of the project and now when I try to build I get the following errors (for some of the projects - not all): Can not find runtime target for framework '.NETCoreApp,Version=v1.0' compatible with one of the target runtimes: 'win10-x64, win81-x64, win8-x64, win7-x64'. Possible causes: 1. The project has not been restored or restore failed - run `dotnet restore` 2. The project does not list one of 'win10-x64, win81-x64,

Injection of IUrlHelper in ASP.NET Core

被刻印的时光 ゝ 提交于 2019-11-27 14:57:58
In RC1 , IUrlHelper could be injected in services (with services.AddMvc() in startup class) This doesn't work anymore in RC2 . Does anybody know how to do it in RC2 as just newing up a UrlHelper requires an ActionContext object. Don't know how to get that outside a controller. For ASP.NET Core RC2 there is an issue for this on the github repo . Instead of injecting the IUrlHelper , take an IUrlHelperFactory . It also sounds like you'd need the IActionContextAccessor injected as a Controller no longer has a public property ActionContext . Register the dependency: services.AddSingleton

Access Web.config settings in Asp.Net Core App?

流过昼夜 提交于 2019-11-27 13:28:33
I understand that asp.net core has a new configuration system that is quite flexible and that's great. But there are things I like about the web.config based configuration system from .net 4.x. For example one can put comments in the web.config file since it's an xml file. And that for me is worth sticking with xml rather than going with the shiny new json approach. [ Update: I now understand that the json approach also supports comments in the file.] So, if I have a Asp.Net Core Web Project that targets the full framework it seems like I should be able to use the web.config based System

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

岁酱吖の 提交于 2019-11-27 12:47:05
问题 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($

JSON properties now lower case on swap from ASP .Net Core 1.0.0-rc2-final to 1.0.0

前提是你 提交于 2019-11-27 12:37:56
问题 I've just swapped our project from ASP .Net Core 1.0.0-rc2-final to 1.0.0. Our website and client have stopped working because of the capitalization of JSON properties. For example, this line of JavaScript now fails for (var i = 0; i < collection.Items.length; i++){ because the controller now calls the array "items" instead of "Items". I have made no changes beyond installing the updated packages and editing the project.json file. I have not changed the C# model files which still capitalize

Override global authorize filter in ASP.NET Core 1.0 MVC

旧时模样 提交于 2019-11-27 12:24:23
I am trying to set up authorization in ASP.NET Core 1.0 (MVC 6) web app. More restrictive approach - by default I want to restrict all controllers and action methods to users with Admin role. So, I am adding a global authorize attribute like: AuthorizationPolicy requireAdminRole = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .RequireRole("Admin") .Build(); services.AddMvc(options => { options.Filters.Add(new AuthorizeFilter(requireAdminRole));}); Then I want to allow users with specific roles to access concrete controllers. For example: [Authorize(Roles="Admin,UserManager")]