Questions tagged «asp.net-core»

ASP.NET Core是一个精简,可组合且跨平台的框架,用于构建Web和云应用程序。它在GitHub上是完全开源的。ASP.NET Core应用程序可以在具有完整.NET Framework或更小的.NET Core的Windows上运行,也可以在具有.NET Core和Mono的Linux和MacOS上运行。

3
Docker:驱动器尚未共享
当“ dockerizing”一个ASP.NET Core 3.1 MVC应用程序时,我得到以下结果: docker run -dt -v "C:\Users\admin\vsdbg\vs2017u5:/remote_debugger:rw" -v "D:\xxx\yyy\Spikes\DockerizedWebApp1\DockerizedWebApp1:/app" -v "D:\xxx\yyy\Spikes\DockerizedWebApp1:/src/" -v "C:\Users\admin\.nuget\packages\:/root/.nuget/fallbackpackages2" -v "C:\Program Files\dotnet\sdk\NuGetFallbackFolder:/root/.nuget/fallbackpackages" -e "DOTNET_USE_POLLING_FILE_WATCHER=1" -e "ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS=true" -e "ASPNETCORE_ENVIRONMENT=Development" -e "NUGET_PACKAGES=/root/.nuget/fallbackpackages2" -e "NUGET_FALLBACK_PACKAGES=/root/.nuget/fallbackpackages;/root/.nuget/fallbackpackages2" -P --name DockerizedWebApp1 --entrypoint tail dockerizedwebapp1:dev -f /dev/null docker: Error response from daemon: status code not OK but 500: {"Message":"Unhandled exception: …

3
枚举类型不再在.Net Core 3.0 FromBody请求对象中工作
我最近将Web API从.Net core 2.2升级到了.Net core 3.0,并注意到当我在端点中将枚举传递给端点时,我的请求现在出错了。例如: 我的api端点具有以下模型: public class SendFeedbackRequest { public FeedbackType Type { get; set; } public string Message { get; set; } } FeedbackType如下所示: public enum FeedbackType { Comment, Question } 这是控制器方法: [HttpPost] public async Task<IActionResult> SendFeedbackAsync([FromBody]SendFeedbackRequest request) { var response = await _feedbackService.SendFeedbackAsync(request); return Ok(response); } …


3
在asp.net core 3.1中基于租户的注册身份验证方案
当前,我已经使用外部登录提供程序创建了Identity Server 4 Web应用程序,该应用程序具有默认客户端ID和机密。但是我的目标是基于租户注册身份验证提供程序,例如Azure,Google,Facebook。 我使用了SaasKit多租户程序集,在这里我尝试了app.usepertenant()中间件。但是UseGoogleAuthentication()方法已过时,因此我无法使用此usepertenant中间件实现多租户身份验证。 当前代码, services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddMicrosoftAccount(option => { option.ClientId = "clientid"; option.ClientSecret = "clientsecret"; option.SaveTokens = true; }); 预期的代码如下所示, var authentication = services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme); if (tenant.hasMicrosoft) { authentication.AddMicrosoftAccount(option => { option.ClientId = "clientid"; option.ClientSecret = "clientsecret"; option.SaveTokens = true; }); } if (tenant.hasGoogle) { authentication.AddGoogle(option => { option.ClientId = …

1
找不到类型或名称空间名称“ IWebHostEnvironment”(您是否缺少using指令或程序集引用?)
我正在使用.NET Core 3.0.100; Microsoft Visual Studio Community 2019预览版本16.4.0预览版1.0; Blazor服务器(官方发行版)。 我正在尝试将身份验证和授权添加到我的Blazor服务器Web应用程序。我在这里阅读指南https://docs.microsoft.com/zh-cn/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-3.0&tabs=visual-studio#scaffold-identity-into-an -空项目 (我也阅读了这个https://github.com/aspnet/Identity/issues/1825) 然后,我右键单击Project,选择Add\New Scaffolded Item... 我读了文件ScaffoldingReadme.txt,然后按照指南进行操作。 我按F5进行调试,发现错误 Severity: Error Error Code: CS0246 Description: The type or namespace name 'IWebHostEnvironment' could not be found (are you missing a using directive or an assembly reference?) Project: foo File: C:\Users\donhuvy\Desktop\foo\bar\obj\Debug\netcoreapp3.0\Razor\Pages\Shared\_Layout.cshtml.g.cs Line: 455 Suppression …

1
从Asp.Net Core控制器返回IAsyncEnumerable <T>和NotFound
对于返回an IAsyncEnumerable&lt;T&gt;和a NotFoundResult但仍以异步方式处理的控制器操作,正确的签名是什么? 我使用了此签名,由于IAsyncEnumerable&lt;T&gt;无法等待,因此无法编译: [HttpGet] public async Task&lt;IActionResult&gt; GetAll(Guid id) { try { return Ok(await repository.GetAll(id)); // GetAll() returns an IAsyncEnumerable } catch (NotFoundException e) { return NotFound(e.Message); } } 这个编译很好,但是它的签名不是异步的。因此,我担心它是否会阻塞线程池线程: [HttpGet] public IActionResult GetAll(Guid id) { try { return Ok(repository.GetAll(id)); // GetAll() returns an IAsyncEnumerable } catch (NotFoundException e) …

3
如何在blazor服务器端本地化验证消息(DataAnnotationsValidator)
我在最新版本的VS 2019中使用blazor 3.1。 到目前为止,我已经可以本地化页面标签(标题,表格字段等)。 在ListEmployee.razor页面中,我能够本地化表格标题等。在AddEmplyeeValidation.razor页面中,我能够本地化表单标签,但是在本地化验证消息时遇到问题。 用于验证消息的Employee.cs验证消息是在此文件和Resources/Data文件夹中定义的,其名称定义为Data.Employee.ar.resx并且Data.Employee.ar.resx无法正常工作 使用System.ComponentModel.DataAnnotations; 命名空间BlazorSPA1.Data {公共类Employee {[MaxLength(50)]公共字符串ID { 组; } [Required (ErrorMessage ="Name is RRRequired")] [StringLength(20, ErrorMessage = "Name is too long.")] public string Name { get; set; } [Required] [StringLength(20)] public string Department { get; set; } [MaxLength(100)] public string Designation { get; set; } [MaxLength(100)] …

2
反向代理404后面的Blazor服务器端
我在反向代理(使用ARR)后面的IIS上托管了一个出色的服务器端应用程序。 我已经尝试了所有可以想到的方法,但是我不断尝试404 _framework / blazor.server.js 我的基本href设置为“ / subsite /”: &lt;base href="https://stackoverflow.com/subsite/" /&gt; 我所有的src值都是相对的,如下所示: &lt;script src="_framework/blazor.server.js"&gt;&lt;/script&gt; &lt;script src="_content/BlazorInputFile/inputfile.js"&gt;&lt;/script&gt; &lt;script src="animations.js"&gt;&lt;/script&gt; 其他所有脚本引用都可以正常加载,即使_content数据也可以加载,但blazor.server.js则不会。 我也尝试了用于MVC应用程序的旧PathBase技巧,但没有成功: if (!env.IsDevelopment()) { app.Use((context, next) =&gt; { context.Request.PathBase = new PathString("/subsite"); return next(); }); } 谁能告诉我如何使Blazor意识到将blazor.server.js放在反向代理场景中的什么位置?


7
带有.NET Core 3.0的Azure Web应用程序失败:找不到Microsoft.AspNetCore.App
升级到.NET Core 3.0后,我们正在尝试部署Web应用程序,但它始终显示“服务不可用”消息。如果尝试dotnet从Kudu(dotnet webapp.dll)运行,则会出现以下错误: It was not possible to find any compatible framework version The specified framework 'Microsoft.AspNetCore.App', version '3.0.0' was not found. - The following frameworks were found: 2.1.10 at [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] 2.1.12 at [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] 2.1.13 at [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] 2.2.5 at [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] 2.2.6 …

3
除了将所有内容添加到Startup类之外,还有一种健壮的方法来在ASP.NET Core 3.1中注册依赖项吗?
我有一个ASP.NET Core 3.1项目。通常,我使用类中的ConfigureServices()方法注册任何依赖Startup.cs项。 但是,我发现自己不得不注册许多依赖项,而且ConfigureServices()看起来很大!我知道我可以创建一个静态方法的扩展方法,并从ConfigureService()类中调用它,但是想知道是否有更好的方法。 如果有一种方法可以在IoC容器中注册依赖项,而不必一次定义它们 services.AddScoped&lt;Interface, Class&gt;(); .... 200 lines later services.AddScoped&lt;ISettings, Settings&gt;()

2
Docker映像在Windows / MVC Core上的构建速度很慢
我有一个MVC Core 2.2,在Docker容器中有多个项目。当我运行它时,大约需要4分钟来构建图像并启动容器。我正在使用docker-compose。 考虑到这是一个很小的发展并且我有一台不错的计算机,所以这似乎很慢。似乎没有使用资源,因为在映像构建期间处理器低于8%,ram不会移动,磁盘几乎为0%。GPU 0%。下载Microsoft映像时,我可以看到互联网激增了几秒钟,仅此而已。我给了docker以下资源: Cores: 8 RAM: 8GB SWAP: 3gb Disk Image Size: 64GB (30.5 GB used) 有什么想法可以利用这些硬件资源来加快构建速度吗?

3
从Visual Studio 2019将ASP.NET Core 3.1网站发布到Azure时出错
我有一个预先存在的ASP.NET Core 3.0应用程序,该应用程序已成功部署到Azure应用程序服务(使用该AspNetCoreModuleV2模块)。将应用程序升级到ASP.NET Core 3.1(今天的发行版)后,该应用程序将在我的本地IIS Express版本上构建并正确运行。但是,当我尝试使用Visual Studio 16.4(今天的版本)发布到Azure App Service 时,出现以下错误: 资产文件“ C:\ Project \ obj \ project.assets.json”没有针对“ .NETCoreApp,Version = v3.0”的目标。确保还原已运行,并且已在项目的TargetFrameworks中包含“ netcoreapp3.0”。 笔记 所有&lt;PackageReference&gt;的到Microsoft.AspNetCore,Microsoft.EntityFrameworkCore和Microsoft.Extensions已被更新到3.1.0 我已经清理了解决方案,甚至删除了我的obj文件夹,以确保没有任何挥之不去的引用。 正在从的3.1.100版本生成此错误Microsoft.PackageDependencyResolution.targets。 我得到的东西仍然挂到.NET 3.0核心的依赖。但是目前尚不清楚为什么这只会在部署期间引起问题。是Azure的应用程序Service的还没有准备好.NET 3.1的核心?还是依赖解决方案目标有问题?

1
澄清IAsyncEnumerable如何与ASP.NET Web API一起使用
在ASP.NET Web API项目中浏览IAsyncEnumerable时遇到了一个有趣的行为。考虑以下代码示例: // Code Sample 1 [HttpGet] public async IAsyncEnumerable&lt;int&gt; GetAsync() { for (int i = 0; i &lt; 10; i++) { await Task.Delay(1000); yield return i; } } // Code Sample 2 [HttpGet] public async IAsyncEnumerable&lt;string&gt; GetAsync() { for (int i = 0; i &lt; 10; i++) { …

1
在Netcore API 3.1中读取AuthorizationFilterContext
我有一个正在运行的netcore 2.2项目,在该项目中,我实施了一个自定义策略来检查API密钥。 在startup.cs中,我要像这样添加此策略 //Add Key Policy services.AddAuthorization(options =&gt; { options.AddPolicy("AppKey", policy =&gt; policy.Requirements.Add(new AppKeyRequirement())); }); 在我的AppKeyRequirement中,我从AuthorizationHandler继承并像这样解析传入请求中的键 protected override Task HandleRequirementAsync(AuthorizationHandlerContext authContext, AppKeyRequirement requirement) { var authorizationFilterContext = (AuthorizationFilterContext)authContext.Resource; var query = authorizationFilterContext.HttpContext.Request.Query; if (query.ContainsKey("key") &amp;&amp; query.ContainsKey("app")) { // Do stuff 在netcore 3.1中不起作用 我收到以下错误: 无法将类型为“ Microsoft.AspNetCore.Routing.RouteEndpoint”的对象转换为类型为“ Microsoft.AspNetCore.Mvc.Filters.AuthorizationFilterContext”的对象。 在核心3及更高版本中执行此操作的正确方法是什么? 正如Kirk Larkin指出的那样,.net 3.0及更高版本中的正确方法是将IHttpContextAccessor注入到Auth处理程序中并使用它。 …

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.