Tag: asp.net core 1.0

通过.NET Core控制台应用程序中的dependency injection访问配置

如何正确激活使用ServiceCollection.Configure函数添加的配置? public static void Main(args[] args) { serviceCollection = new ServiceCollection(); serviceCollection .Configure(Configuration.GetSection(“options”)); Services = serviceCollection.BuildServiceProvider(); ActivatorUtilities.CreateInstance(Services); ActivatorUtilities.CreateInstance(Services); } public SomeClassThatNeedsoptions(IOptions options) { _options = options.Value; } 在第二个ActivatorUtilities.CreateInstance我收到以下错误 无法解析类型’Microsoft.Extensions.Options.IOptions [MyOptions]`的服务 我在控制台应用程序中写这个,据我所知,我使用ActivatorUtilities类手动注入依赖项。 我似乎能够使用添加了AddSingleton的服务来完成它,而不是使用.Configure添加的服务

asp.net mvc core以下方法或属性之间的调用不明确:

我正在处理一个应用程序,我在Startup.cs部分类中遇到错误,我无法找到为什么会出现此错误: 以下方法或属性之间的调用不明确:Microsoft.Extensions.DependencyInjection.OptionsServiceCollectionExtensions.Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action)Microsoft.Extensions.DependencyInjection.OptionsServiceCollectionExtensions.Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection) ,System.Action) 我的两个部分Startup.cs类是 using Microsoft.Extensions.DependencyInjection; using System.Security.Claims; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; namespace GiftUWish.WebAPI { public partial class Startup { private void SetServices(IServiceCollection services) { //PROFILE service and repository services.AddScoped(); services.AddScoped(); ////GIFT service and repository services.AddScoped(); services.AddScoped(); //EVENT service and repository services.AddScoped(); services.AddScoped(); //CREDIT CARD INFORMATION serice and repository services.AddScoped(); services.AddScoped(); //CHIPPED IN serive and […]

ActionContext在Microsoft.AspNetCore.Mvc.Controller中消失了

我无法在Microsoft.AspNetCore.Mvc.Controller中找到ActionContext 之后我将我的版本更改为AspNetCore 1.0.0-preview1 这是Controller类(更改后): 并且在更改之前从“ Microsoft.AspNet.Mvc ”: 更新前的旧方法代码: this.Agent = ControllerInfo.Request.Headers[“User-Agent”]; this.IP = ControllerInfo.HttpContext.Features.Get()?.LocalIpAddress?.ToString(); this.RemoteIP = ControllerInfo.HttpContext.Features.Get()?.RemoteIpAddress.ToString(); this.Refrence = ControllerInfo.ActionContext.RouteData.Values[“controller”].ToString() + “/” + ControllerInfo.ActionContext.RouteData.Values[“action”].ToString();

在完整的.NET框架上测试Asp.Net Core

我想对一个针对完整的.net框架的asp.net核心项目进行unit testing。 我尝试使用本博文中概述的“普通”unit testing项目模板和.net核心项目,但两次尝试均失败,因为我的Web项目的程序集无法在任何一个测试项目中引用。 有没有办法在完整框架上unit testingasp.net核心应用程序?

ASP.NET CORE 1.0,模拟

我正在写一个Intranet应用程序。 project.json中的目标框架是dnx451。 这是我的发布命令: dnu publish –runtime dnx-clr-win-x86.1.0.0-rc1-update1 –no-source Database Connection字符串: Server=name;Database=name;Trusted_Connection=True; 我正在尝试模拟数据库访问,但它无法正常工作。 当我启动应用程序时,我的Windows用户被识别,它在右上角显示Hello,Domain \ Username。 一旦我尝试访问数据库,我就会收到错误“登录用户域\ Computername失败”。 如果我在我的用户下运行应用程序池,那么一切正常。 IIS:.NET CLR Versio是v4.0,托管Pipline模式Classic和Identity是ApplicationPoolIdentity。 网站身份validation:启用了ASP.NET模拟和Windows身份validation。 我需要做些什么才能改变模仿终于有效?

将ASP.NET Core 1.0更新为1.1后出现HTTP 502.5错误

重现步骤 我使用这个官方ASP.NET和本文将我的ASP.NET Core 1.0应用程序升级到1.1。 该应用程序编译正常,但当我使用F5运行应用程序时,我收到以下错误 错误 : HTTP Error 502.5 – Process Failure Common causes of this issue: The application process failed to start The application process started but then stopped The application process started but failed to listen on the configured port 更多技术细节 操作系统:Windows 10 Visual Studio版本:2015-Update 3(包含最新更新) 注意 : 我的应用程序是在默认内置IIS Express上运行的开发机器(Windows 10)上。 不涉及服务器或迁移到其他服务器。 […]

无法使用Asp.NET Core中的Entity Framework添加带有视图的Scaffold> MVC Controller

当我尝试使用内置生成器添加Controller时,我收到以下错误消息: 其中“Brand”是模型类,“ApplicationDbContext”是我的数据上下文类。 我从来没有像这样经历过这样的错误。 它不会一直发生(2次成功与30-40次尝试而不更改单行代码)。 我能够在几分钟之前为同一个类创建Controller,但是当你尝试添加新内容并尝试超过10次而没有结果时,它真的很烦人。 当然,我可以编写自己的控制器和视图,但我真的很喜欢使用附带的工具。 我已经使用“添加或删除”中的“修改”选项修复了VS. 我正在使用最新的Microsoft Visual Studio社区(MVSC2015 V14.0.25425.01 Update3)。 编辑: Brand.cs: namespace AppBrander.Models { public class Brand { public int ID { get; set; } public string Email { get; set; } public string BrandName { get; set; } public string CompanyName { get; set; } public string Description { get; set; […]

.Net Core MVC应用程序中的System.Runtime引用

我最近将我的.Net Core(我相信10 RTM,1.0.0-preview2-003121?)MVC解决方案更新到VS2017解决方案。 经过多次尝试,使用多个project.json版本和.Net Core软件包版本,我终于让应用程序在新环境中再次运行。 当然,除了在我的Razor视图中使用某些对象时仍然弹出1个错误: 如您所见,错误表明我缺少对System.Runtime的引用。 我尝试以多种方式将此引用添加到我的项目中,但到目前为止都没有工作:(。我尝试过: – 使用System.Runtime NuGet包 – 在我的csproj文件中添加程序集引用 – 通过浏览到dll添加程序集引用在我的电脑上 – 将DLL复制到我在我的解决方案中找到的每个bin文件夹 有没有人有同样的问题和/或知道解决这个问题的方法?

路由控制器和中间件中的操作

我正在尝试检索控制器和操作,我已经通过使用尝试了这一点 var routeData = context.GetRouteData(); 在中间件的Invoke方法中,但每次都会产生null。 是否有可能在中间件中检索路由数据? 我想要实现的是检查请求的操作是否具有[RequireToken]属性,如果是,它将检查特定标记的传入标头。

指定asp.net核心1.0 WebAPI.exe应该在program.cs中为prod和dev使用的url(端口)

我在我的asp.net core 1.0 web api(.NET Framework)program.cs中执行以下操作,以指定我希望我的web api exe运行的端口仅用于开发目的: public static void Main(string[] args) { var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup() .UseUrls(new string[1] { “http://*:12012” }) .Build(); host.Run(); } 但是,当我发布到生产时,这行会导致WebAPI出错,因为我希望exe使用生产web-api url即productionWeb / api / values而不是localhost:12012 / values 无论如何,我可以得到两个世界中最好的能够指定我希望它在端口12012上运行以用于开发目的和生产URL用于产品目的吗? 我目前的解决方案是在发布之前注释掉该行。