Tag: asp.net core

从csproj引用xproj

我在visual studio中添加了csproj到xproj引用。 我看到引用中的库和dll的路径是正确的。 Intelisens工作,但编译无法使用错误: the type could not be found. 我该如何投入使用?

dependency injectionUserManager正在处理异步调用(ASP.NET CORE)

我正在使用ASP.NET Core及其内置的dependency injection和asp.net身份。 我遇到的问题是每当我尝试通过异步访问任何上下文时(即在此示例中为UserManager ),它在访问时都会被处理掉。 例如,我的控制器在下面(我们关注的对象是UserManager ) private readonly ApplicationDbContext _dbContext; private readonly UserManager _userManager; private readonly ViewRender _view; private readonly IConfiguration _config; public UserController(ApplicationDbContext dbContext, UserManager userManager, ViewRender view, IConfiguration config) { this._dbContext = dbContext; this._userManager = userManager; this._view = view; this._config = config; } 请注意,正在使用startup.cs中的visual studio模板默认设置注入_userManager 现在在这个控制器的方法中我尝试以下方法: [HttpDelete] public async void Delete(string id) […]

ViewComponent和InvokeAsync方法

在下面的方法中,我收到警告 : This async method lacks ‘await’ operators and will run synchronously 。 我在哪里可以使用await这个方法? 注意 :此方法返回一个简单的静态视图,而不与数据库等交互。 public class TestViewComponent : ViewComponent { public async Task InvokeAsync() { return View(); } }

通过.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 core从构建中排除文件

我正在尝试将Protractor添加到我的asp.net核心应用程序中。 我通过npm添加它,它安装了包含文件Page.aspx.cs的selenium-webdriver。 这导致了构建错误,但我的项目甚至不需要编译它。 所以我试图使用project.json排除node_modules “buildOptions”: { “emitEntryPoint”: true, “preserveCompilationContext”: true, “compile”: { “excludeFiles”: “node_modules” } }, Illegal characters in path给出Illegal characters in path如下所示: “excludeFiles”: [“node_modules”] 这似乎与_字符有关,但我无法弄清楚为什么这会是一个问题。 谢谢

ASP.NET核心本地化 – 不从资源文件返回值,仅返回Name

我正在尝试实现本地化,但是在运行时只返回Name。 Startup.cs public void ConfigureServices(IServiceCollection services) { services.AddLocalization(options => options.ResourcesPath = “Resources”); services.AddMvc() .AddViewLocalization() .AddDataAnnotationsLocalization(); } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { ….. List supportedCultures = new List { new CultureInfo(“no”), new CultureInfo(“en”) }; app.UseRequestLocalization(new RequestLocalizationOptions { DefaultRequestCulture = new RequestCulture(“no”), SupportedCultures = supportedCultures, SupportedUICultures = supportedCultures }); app.UseStaticFiles(); app.UseMvc(routes => { […]

运行时服务不再注入DNX控制台应用程序(RC1)

我曾经能够将运行时服务(如IApplicationEnvironment注入DNX控制台应用程序的Pogram类的构造函数中。 但是,使用RC1的最新CI版本,服务不再被注入: public Program(IApplicationEnvironment env) { if (env == null) { // env is null. throw new ArgumentNullException(nameof(env)); } }

从csproj引用ASP.NET xproj

我正在使用Visual Studio中新的“类库(NuGet包)”模板之一,我想为它创建一个xUnit测试库。 问题是,当我创建一个新的.csproj库并尝试引用.xproj包时,Visual Studio说”The reference to XXXX could not be resolved.” 为什么会发生这种情况,我该怎么做才能解决这个问题?

EmailAttribute未在ASP.NET Core的ViewModel中正确validation

这是位于我的viewmodel中的字段: [Required(ErrorMessage = “Email is missing.”), EmailAddress(ErrorMessage = “Email is not valid.”)] public string Email { get; set; } ( EmailAddress来自EmailAddressAttribute.EmailAddressAttribute()类型) 这是HTML的相关部分: EMAIL 当我在电子邮件文本框中输入myemail时,它会说 电子邮件无效 但是,在键入myemail@email ,视图模型将会将其视为正确(仅在前端)。 public async Task Register([FromForm]VisitViewModel vm) 像这样的ModelState转换会使ModelState无效并拒绝电子邮件,因此该部分是可以的。 根据这个答案 ,前端应该表明这是无效的 谁能解释一下这里发生了什么? 我绝对亏本。

Linux上的.net核心应用程序目标.net框架4.5.2

我想更多地了解点网核心支持。 我的基本理解是,如果我想在Linux上运行.net应用程序,那么需要构建.net核心和目标netcoreapp1.0框架来保证这一点。 1)我假设上述假设是正确的? 2)当我在线阅读各种文章时,例如关于在.net核心应用程序中引用退出.net框架项目的文章( https://www.hanselman.com/blog/HowToReferenceAnExistingNETFrameworkProjectInAnASPNETCore10WebApp.aspx )如果我这样做,大概是该应用程序只能在Windows而不是Linux上运行? 3)在以下文章中: https : //blogs.msdn.microsoft.com/cesardelatorre/2016/06/28/running-net-core-apps-on-multiple-frameworks-and-what-the-target-framework -monikers-tfms-are-about /在运行.net运行4.5.2选项( dotnet run -f NET452 )的dotnet run -f NET452 ,提到: 如果这个应用程序在.NET核心平台上运行,让我们说在Linux机器或Mac上,这个代码将不会被执行,但该应用程序仍将在Linux或MacOS上运行。 运行和不执行之间的区别是什么? 如果我的初步理解是正确的,那么通过在Linux上运行.net 4.5.2选项,我不希望应用程序根本不运行。 欣赏那里的几个问题,但真的想要了解更多.net核心。