在从 .net core 2.2 切换到 3.0,然后在本地切换到 3.1 之后,我们切换到端点路由。我有以下路线:
app.UseEndpoints(endpoints =>
{
// Using this for asp.net core identity
endpoints.MapRazorPages();
// Mapping 2 routes, one private, one public but that we don't want localized so in both cases was simpler to create an area
endpoints.MapAreaControllerRoute("Back", "Back", "back/{controller=Home}/{action=Index}/{id?}");
endpoints.MapAreaControllerRoute("Photo", "Photo", "photo/{controller=Photo}/{action=Index}/{id?}");
// The default mapping for our front office, this works just fine in iis express
endpoints.MapControllerRoute("default", "{lang:lang}/{controller=Home}/{action=Index}/{id?}");
// Fallback is used mainly to redirect you from / to /defaultlanguage
endpoints.MapFallbackToController("WrongEndpoint","Home");
}); …Run Code Online (Sandbox Code Playgroud) 我有这个 Seeder 类,它在 Configure 方法的 Startup.cs 文件的末尾被调用:
public class UserSeeder
{
private readonly ApplicationDbContext _context;
private readonly UserManager<ApplicationUser> _userManager;
public UserSeeder(ApplicationDbContext context, UserManager<ApplicationUser> userManager)
{
_context = context;
_userManager = userManager;
}
public async Task Seed()
{
if (!await _context.Users.AnyAsync())
{
var user = new ApplicationUser()
{
UserName = "admin",
Email = "admin@test.com"
};
await _userManager.CreateAsync(user, "passwort4admin");
}
}
}
Run Code Online (Sandbox Code Playgroud)
代码被执行,我什至在方法调用周围放置了一个 try/catch 但没有发生错误并且没有用户插入到数据库中!
为什么不?
我正在学习服务器端 blazor 并尝试学习身份验证。每当我使用 SignInManager.SignInAsync(.......) 时,它都会引发以下异常:
System.InvalidOperationException:无法修改响应标头,因为响应已开始。 在 Microsoft.AspNetCore.HttpSys.Internal.HeaderCollection.ThrowIfReadOnly() 在 Microsoft.AspNetCore.HttpSys.Internal.HeaderCollection.set_Item(String key, StringValues value) 在 Microsoft.AspNetCore.Http.ResponseCookies.Append(String key, String value, CookieOptions 选项) 位于 Microsoft.AspNetCore.Authentication.Cookies.ChunkingCookieManager.AppendResponseCookie(HttpContext context、String key、String value、CookieOptions options) 位于 Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler.HandleSignInAsync(ClaimsPrincipal 用户、AuthenticationProperties 属性) 位于 Microsoft。 AspNetCore.Authentication.AuthenticationService.SignInAsync(HttpContext 上下文、字符串方案、ClaimsPrincipal 主体、AuthenticationProperties 属性) 位于 Microsoft.AspNetCore.Identity.SignInManager
1.SignInWithClaimsAsync(TUser user, AuthenticationProperties authenticationProperties, IEnumerable1 extraClaims),位于 C:\my_work\Blazor_learning\GroupMembersInfo 中的 GroupMembersInfo.Pages.RegisterUser.Register() \Pages\RegisterUser.razor:第 52 行位于 Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(任务任务)位于 Microsoft.AspNetCore.Components.Forms.EditForm.HandleSubmitAsync()
位于 Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(任务任务) )在 Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(任务 taskToHandle)
我认为异常是从我突出显示的方法中抛出的。那么我该如何缓解这个问题。这是我的代码
启动程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using …Run Code Online (Sandbox Code Playgroud) 我有一个非常大的JSON文件,现在下面的汽车数组可以达到100,000,000条记录.文件总大小可以从500mb到10GB不等.我正在使用Newtonsoft json.net
输入
{
"name": "John",
"age": "30",
"cars": [{
"brand": "ABC",
"models": ["Alhambra", "Altea", "AlteaXL", "Arosa", "Cordoba", "CordobaVario", "Exeo", "Ibiza", "IbizaST", "ExeoST", "Leon", "LeonST", "Inca", "Mii", "Toledo"],
"year": "2019",
"month": "1",
"day": "1"
}, {
"brand": "XYZ",
"models": ["Alhambra", "Altea", "AlteaXL", "Arosa", "Cordoba", "CordobaVario", "Exeo", "Ibiza", "IbizaST", "ExeoST", "Leon", "LeonST", "Inca", "Mii", "Toledo"],
"year": "2019",
"month": "10",
"day": "01"
}],
"TestCity": "TestCityValue",
"TestCity1": "TestCityValue1"}
Run Code Online (Sandbox Code Playgroud)
期望的输出 文件1 Json
{
"name": "John",
"age": "30",
"cars": {
"brand": "ABC",
"models": ["Alhambra", "Altea", …Run Code Online (Sandbox Code Playgroud) 快速答复将不胜感激。这是我的 tsconfig.json 文件
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
}
}
Run Code Online (Sandbox Code Playgroud) 我想在 Dot Net core 3.1 中执行一个带有输出参数的存储过程。我正在使用类的ExecuteSqlInterpolated扩展方法DatabaseFacade。
获取员工人数的 C# 代码。
string deptName="IT";
int? employeeCount = null;
Database.ExecuteSqlInterpolated($"exec dbo.usp_GetEmpCountByDept {deptName}, {employeeCount} out");
Run Code Online (Sandbox Code Playgroud)
执行后employeeCount 是null和-1是返回值。由于有些人要求存储 proc 代码来重现该问题,因此我将 proc 存储如下
CREATE PROCEDURE usp_GetEmpCountByDept
@Dept nvarchar(20),
@EmpCount int Output
AS
BEGIN
SELECT @EmpCount = COUNT(Id)
FROM [dbo].[Employees]
WHERE Department = @Dept
END
Run Code Online (Sandbox Code Playgroud) 谁能建议如何从任何单行语句中删除大括号?(排除明显的手动删除大括号)
在 Visual Studio 中使用 C#。
所以而不是:
if (thingy is null)
{
throw new ArgumentNullException(nameof(thingy));
}
Run Code Online (Sandbox Code Playgroud)
有替代方案:
if (thingy is null)
throw new ArgumentNullException(nameof(thingy));
Run Code Online (Sandbox Code Playgroud)
我尝试运行 CodeMaid 并更改 CodeCleanup (这只是将其更改回大括号)。我很高兴尝试任何推荐的扩展等来解决这个问题。
我有一个问题,我正在 net core 中创建一个应用程序来上传孩子的信息,但是,主要问题是我拥有的所有图像都来自我的手机,你知道我们谈论的是每张图片 9-15 MB ,所以,我知道我不能告诉用户“有一个限制”,但是,我认为它没有用,所以,有一种方法可以减少图像的大小,从而降低质量吗?。
这是我的方法
班级
public IFormFile ImageFile { get; set; }
Run Code Online (Sandbox Code Playgroud)
方法
if (vm.ImageFile != null && vm.ImageFile.Length > 0)
{
var guid = Guid.NewGuid().ToString();
var file = $"{guid}.jpg";
path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\Kids", file);
using (var stream = new FileStream(path, FileMode.Create))
{
//var convertedImage = MagicSolutionGivenByTheAwsomeStackOverFlowCommunity
await vm.ImageFile.CopyToAsync(stream);
}
}
Run Code Online (Sandbox Code Playgroud)
布局
<form asp-action="Create" enctype="multipart/form-data">
<input type="hidden" asp-for="Imagen"/>
<div class="col-sm-4">
<label asp-for="Imagen" class="control-label"></label>
<div>
<input asp-for="ImageFile" class="form-control filestyle"
type="file" data-classbutton="btn btn-secondary"
data-classinput="form-control inline"
data-icon="<span class='fa fa-upload …Run Code Online (Sandbox Code Playgroud) 我正在使用 Airflow 在 Google Cloud Composer 上运行 Spark 作业。我需要
使用 Airflow API - 我可以读取 YAML 文件,并使用 xcom 跨任务推送变量。
但是,考虑 DataprocClusterCreateOperator()
cluster_nameproject_idzone和其他一些参数被标记为模板化。
如果我想将其他参数作为模板传递(目前不是这样)怎么办?-样image_version,
num_workers,worker_machine_type等?
有什么解决方法吗?
google-cloud-platform airflow google-cloud-composer apache-airflow-xcom
我想在我的应用程序中包含字体真棒图标。
我正在使用 expo 构建本机应用程序。
文档说明我不需要安装很棒的字体,但我确实需要导入并正确使用语法。
任何帮助将不胜感激。
import { FontAwesome } from '@expo/vector-icons';
<TabBarIcon
focused={focused}
name={Platform.OS === 'ios' ? 'fa-newspaper-o' : 'md-link'}
/>
Run Code Online (Sandbox Code Playgroud)
我做错了,因为图标没有显示出来。
当我在请求中未使用别名时,收到错误“FieldsConflict 类型的验证错误”。请确认这是否是预期的情况或是否有解决方法
{
person(search: [{firstname: "DAN", lastname: "WATLER", country: "FRANCE"}])
{
firstname
lastname
country
age
address
}
person(search: [{firstname: "FRANK", lastname: "TEE", country: "FRANCE"}])
{
firstname
lastname
country
age
address
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码给出了验证错误,但如果我使用下面所示的别名,错误不会出现,并且我会得到成功的响应。
我不想使用别名,请建议是否有任何解决方法。谢谢 !
{
dan: person(search: [{firstname: "DAN", lastname: "WATLER", country: "FRANCE"}])
{
firstname
lastname
country
age
address
}
frank: person(search: [{firstname: "FRANK", lastname: "TEE", country: "FRANCE"}])
{
firstname
lastname
country
age
address
}
}
Run Code Online (Sandbox Code Playgroud) 我可以使用类似的代码和不记名令牌执行 GET,但似乎无法执行 POST。
当我将 Json、URL 和 Bearer Token 复制/粘贴到 Postman 时,它运行良好。但是当从 C# 执行它时,我收到此错误:
“StatusCode: 400, ReasonPhrase: ‘Bad Request’, Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Transfer-Encoding: chunked Connection: keep-alive Expect-CT: max-age=604800, report -uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" CF-RAY:4c190ad8ad786539-SYD 日期:2019 年 4 月 3 日星期三 06:38:54 GMT Set-Cookie: __cfduid=dc0232e99fa0fefc0bd728258229dd5d51554273534; expires=Thu, 02-Apr-20 06:38:54 GMT; path=/; domain=.paymentsapi.io; HttpOnly; Secure Server:应用程序/json;字符集=utf-8 }"
谁能看到我做错了什么?
提前致谢。
JsonSerializerSettings jss = new JsonSerializerSettings();
string strValue = JsonConvert.SerializeObject(TestMaster, jss);
lblJSon.Text = strValue; // This Json is valid
ByteArrayContent bytecontent = new ByteArrayContent(System.Text.Encoding.UTF8.GetBytes(strValue));
bytecontent.Headers.ContentType = …Run Code Online (Sandbox Code Playgroud) 我使用 ForEach 循环从 3 个不同的 URL 返回状态代码以遍历结果。它返回的结果很好,但返回了 3 组结果。
public static List<Models.SiteStatus> GetStatus()
{
statusList.Clear();
// website urls to check
string site1 = "https://www.google.com";
string site2 = "https://www.google.com";
string site3 = "https://www.google.com";
int site1Status = 0;
int site2Status = 0;
int site3Status = 0;
HttpStatusCode result = default;
HttpWebResponse response = null;
// add urls to a list to pass through
List<Uri> urls = new List<Uri>();
urls.Add(new Uri(site1));
urls.Add(new Uri(site2));
urls.Add(new Uri(site3));
// check status per site
foreach (Uri u …Run Code Online (Sandbox Code Playgroud) c# ×8
asp.net-core ×4
.net-core ×2
json ×2
.net ×1
airflow ×1
angular ×1
api ×1
arrays ×1
asp.net ×1
bearer-token ×1
code-cleanup ×1
codemaid ×1
curly-braces ×1
expo ×1
font-awesome ×1
foreach ×1
graphql ×1
graphql-java ×1
iis ×1
json.net ×1
post ×1
react-native ×1