小编Jaz*_*azb的帖子

使用.netcore 2.2并使用`In Process`托管模型

我正在尝试使用.net core sdk 2.2附带的新功能,据称这可以将性能提高大约400%.

令人印象深刻,所以我在我的ABP项目上试了一下

Template asp.net core mvc 4.0.2.0

我在web.mv.cproj文件中添加了以下内容

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
  </ItemGroup>
Run Code Online (Sandbox Code Playgroud)

不幸的是,我不认为这个版本的ABP框架是兼容的,因为项目根本无法运行和抛出:(最终)

HTTP错误500.30 - ANCM进程内启动失败

stdoutLogEnabled="true"在web.config中设置并重新尝试后检查了日志- 但没有条目.

有没有人在流程设置中对asp.net核心运行当前的ABP有什么成功?

我想这可能是ABP vNext中唯一可用的东西.

.net-core aspnetboilerplate

37
推荐指数
8
解决办法
4万
查看次数

我可以使用 System.Text.Json 通过私有构造函数反序列化 Json 吗?

想知道是否可以拥有私有构造函数并使用新的 System.Text.Json 序列化器。

public class MyModel
{
    public string Name { get; set; }
    public string Data { get; set; }

    private MyModel() 
    {
        // use me for when deserializing
    }

    public MyModel(string name, string data)
    {
        Name = name;
        Data = data;
    }
}
Run Code Online (Sandbox Code Playgroud)

简单的往返。

var model = new MyModel("doo", "doo");
var json = JsonSerializer.Serialize(model, new JsonSerializerOptions
{
    WriteIndented = true
});

// no to go because of there is no parameterless constructor defined for this object.
var rehydrated …
Run Code Online (Sandbox Code Playgroud)

c# .net-core system.text.json

17
推荐指数
2
解决办法
1万
查看次数

ASP.NET Core 3.0 中的 JsonOutputFormatter

在asp.net core 2.2中,我曾经有以下内容,

  var jsonSettings = new JsonSerializerSettings
  {
    ContractResolver = new SubstituteNullWithEmptyStringContractResolver()
  };

services.AddMvc(options =>
{
        options.OutputFormatters.RemoveType<JsonOutputFormatter>();
        options.OutputFormatters.Add(new ResponseJsonOutputFormatter(jsonSettings,ArrayPool<char>.Shared));
}

public class ResponseJsonOutputFormatter : JsonOutputFormatter
{
 // Stuff in here
}
Run Code Online (Sandbox Code Playgroud)

但是在 3.0 中使用:

services.AddControllersWithViews(options =>
Run Code Online (Sandbox Code Playgroud)

并且类型JsonOutputFormatter不再可用。

当前建议的全局自定义 json 响应的方法是什么?

我尝试使用IOutputFormatter但是当我将它设置AddControllersWithViews为 OutputFormatters时它似乎没有连接,所以不确定是否有额外的步骤?

具有新端点路由的中间件是一种选择吗?或者有没有更好的方法来实现这一目标?

c# json asp.net-core-3.0

12
推荐指数
1
解决办法
3552
查看次数

ValueTuple命名约定

命名ValueTuple元素时是否约定是否应大写?

(string Name, int Index) rec;
Run Code Online (Sandbox Code Playgroud)

要么

(string name, int index) rec;
Run Code Online (Sandbox Code Playgroud)

谢谢

c# naming-conventions c#-7.0

11
推荐指数
1
解决办法
705
查看次数

使用 List&lt;string&gt; 类型作为 DataRow 参数

我们如何将 a 传递List<string>DataRow参数[DataTestMethod]

我正在尝试类似的东西:

[DataTestMethod]
[DataRow(new List<string>() {"Iteam1"})]
[TestCategory(TestCategories.UnitTest)]
public void MyTest(IEnumerable<string> myStrings)
{
// ...    
}
Run Code Online (Sandbox Code Playgroud)

我收到编译错误:

属性参数必须是属性参数类型的常量表达式、typeof 表达式或数组创建表达式

甚至有可能像这样传递 List 吗?

c# parameters attributes unit-testing list

8
推荐指数
2
解决办法
6528
查看次数

dotnet new 的多项目模板

我正在创建一个多项目模板,其中包含一些可选项目和解决方案文件夹。我已经通过 github 中的很多不同的文档和代码来实现这一点,但收效甚微。我真的很感激有人能给我一些关于这些问题的澄清吗?

  1. VSTemplate xml 文件是否仍然相关? 这个博客建议在 template.json 文件中进行更改,但是当我在github 中检查示例时,人们使用 VSTemplate 创建项目,并且 SideWaffle 插件仍然创建了 VSTemplate 文件。如果它仍然相关,想知道它与 json 文件有何不同?
  2. 使用上面的 VSTemplate 我试图创建一个多项目模板,使用 ProjectCollection 标签,当我运行 dotnet run 命令时,模板被执行但项目没有被创建。

    <ProjectTemplateLink ProjectName="$safeprojectname$.Forms.Plugin.Abstractions">
      Forms.Plugin.Abstractions\Forms.Plugin.Abstractions.vstemplate
    </ProjectTemplateLink>
    <ProjectTemplateLink ProjectName="$safeprojectname$.Forms.Plugin.iOS">
      Forms.Plugin.iOS\Forms.Plugin.iOS.vstemplate
    </ProjectTemplateLink>
    <ProjectTemplateLink ProjectName="$safeprojectname$.Forms.Plugin.iOSUnified">
      Forms.Plugin.iOSUnified\Forms.Plugin.iOSUnified.vstemplate
    </ProjectTemplateLink>
    <ProjectTemplateLink ProjectName="$safeprojectname$.Forms.Plugin.Android">
      Forms.Plugin.Android\Forms.Plugin.Android.vstemplate
    </ProjectTemplateLink>
    <ProjectTemplateLink ProjectName="$safeprojectname$.Forms.Plugin.WindowsPhone">
      Forms.Plugin.WindowsPhone\Forms.Plugin.WindowsPhone.vstemplate
    </ProjectTemplateLink>
    </ProjectCollection>```
    
    Run Code Online (Sandbox Code Playgroud)

我们可以使用 template.json 文件创建多项目模板吗?

如果有人能帮助我开始,将不胜感激。

.net c# templates visual-studio visual-studio-templates

7
推荐指数
1
解决办法
1931
查看次数

登录 Blazor 服务器端应用程序不起作用

我正在为 Asp.net 核心 3.0 Blazor 服务器端应用程序构建示例登录 razor 组件。每当代码到达 SignInAsyc 方法时,它似乎只是挂起或锁定,因为代码停止进一步执行。我还尝试通过使用 PasswordSignInAsync 方法来切换逻辑,这给了我完全相同的结果。所有代码都将在该方法之前执行,但在执行该语句时会冻结。我在这里缺少什么?

Razor 组件页面:

<div class="text-center">
    <Login FieldsetAttr="fieldsetAttr" UsernameAttr="usernameAttr" PasswordAttr="passwordInput"
           ButtonAttr="buttonAttr" ButtonText="Sign In" InvalidAttr="invalidAttr" />

</div>

@code {
    Dictionary<string, object> fieldsetAttr =
        new Dictionary<string, object>()
        {
            {"class", "form-group" }
        };

    Dictionary<string, object> usernameAttr =
        new Dictionary<string, object>()
        {
            {"class", "form-control" },
            {"type", "text" },
            {"placeholder", "Enter your user name here." }
        };

    Dictionary<string, object> passwordInput =
        new Dictionary<string, object>()
        {
            {"class", "form-control" },
            {"type", "password" }
        };

    Dictionary<string, object> buttonAttr …
Run Code Online (Sandbox Code Playgroud)

c# blazor-server-side asp.net-core-3.0

7
推荐指数
2
解决办法
4838
查看次数

如何使用 .Net Core 识别 Linux/Mac 机器的硬件详细信息

如何使用 .Net Core 识别 Linux/Mac 机器的硬件详细信息。

对于windows机器,我们可以使用System.ManagementWMI Query。

那么有没有类似的方法来识别 Linux 和 Mac 机器的硬件细节(如 RAM、处理器、监视器、CAM 等)。

对于 Windows,我正在使用:

ManagementObjectSearcher searcher = 
    new ManagementObjectSearcher("select * from Win32_Processor");
Run Code Online (Sandbox Code Playgroud)

.net c# hardware .net-core

6
推荐指数
1
解决办法
1550
查看次数

有效电子邮件地址的数据注释

我正在为我的表单使用数据注释,用户可以在其中注册他们的帐户。对于电子邮件字段,我有一个用于必需的数据注释和一个用于有效电子邮件的数据注释。在这里你可以在我的视图模型中看到:

    [Required(ErrorMessage = "The Email field is required.")]
    [EmailAddress(ErrorMessage = "The Email field is not a valid e-mail address.")]
    public string Email { get; set; }
Run Code Online (Sandbox Code Playgroud)

在我看来,我有以下代码:

<form asp-controller="Home" asp-action="RegisterAsync" method="post" class="register-form">
    <br />
    <img src="~/images/logo.png" width="300" />
    <br />
    <br />

    <div class="text-danger">
        @ViewBag.FailedToRegister
    </div>

    <div class="form-group">
        <input asp-for="Name" placeholder=@Localizer["Name"] class="form-control" />
        <span asp-validation-for="Name" class="text-danger"></span>
    </div>

    <div class="form-group">
        <input asp-for="Email" placeholder="Email" class="form-control" />
        <span asp-validation-for="Email" class="text-danger"></span>
    </div>
// Removed code for brevity
Run Code Online (Sandbox Code Playgroud)

现在,当我运行我的应用程序并将电子邮件字段留空时,我会收到一条如下所示的不错的错误消息。

更正电子邮件错误消息

但是,当我填写的内容不是有效的电子邮件地址时,我不会收到与上面相同的错误文本,但会收到以下信息。

错误的电子邮件错误消息

(对不起,荷兰语消息,这意味着:需要一个有效的电子邮件地址。)

但是为什么我没有收到我在 ViewModel 中编程的消息,我该如何解决这个问题?

我也尝试改变 …

c# asp.net-core-mvc

6
推荐指数
1
解决办法
5557
查看次数

ASP.NET Core 2.1 - 身份验证 cookie 已删除,但用户仍然可以登录而无需重定向到外部登录

再会!我目前正在创建一个网站,该网站利用 Google 身份验证来实现内容个性化。我在登录和检索登录用户信息方面没有问题,但当我调用 SignOutAsync() 函数时,.NET 并未完全注销用户,因为用户再次单击“登录”按钮时可以立即登录。清除浏览器缓存后,用户单击“登录”按钮时将被重定向到 Google 登录页面。

Startup.cs 中的服务配置:

public void ConfigureServices(IServiceCollection services)
    {
        services.Configure<CookiePolicyOptions>(options =>
        {
            // This lambda determines whether user consent for non-essential cookies is needed for a given request.
            options.CheckConsentNeeded = context => true;
            options.MinimumSameSitePolicy = SameSiteMode.None;
        });

        // Configure authentication service
        services.AddAuthentication(options =>
        {
            options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            options.DefaultChallengeScheme = "Google";
        })
            .AddCookie("Cookies")
            .AddGoogle("Google", options =>
            {
                options.ClientId = Configuration["Authentication:Google:ClientId"];
                options.ClientSecret = Configuration["Authentication:Google:ClientSecret"];
            });

        services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
        services.AddSingleton<IRecommender, OntologyRecommender>();

        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
    }
Run Code Online (Sandbox Code Playgroud)

Startup.cs 中的中间件配置: …

c# authentication google-authentication asp.net-core-mvc asp.net-core

5
推荐指数
1
解决办法
5382
查看次数