小编Ali*_*liK的帖子

Blazor 服务器端 Console.WriteLine 不起作用

我想知道我是否遗漏了什么,但刚刚启动了服务器端 Blazor 的基本模板,发现 Console.WriteLine 不起作用。我的意思是我在 Chrome 控制台中看不到文本。

@code{

    protected override async Task OnInitializedAsync() 
    {
        System.Console.WriteLine("oninit");
    }
}
Run Code Online (Sandbox Code Playgroud)

blazor

8
推荐指数
3
解决办法
1万
查看次数

覆盖asp.net核心1.1中的现有数据注释属性

我试图覆盖RequiredAttribute.net核心,似乎不适用于asp.net核心1.1

这是测试代码

public class CustomRequiredAttribute : RequiredAttribute
{
    public CustomRequiredAttribute():base()
    {

    }

    public override string FormatErrorMessage(string name)
    {
        return base.FormatErrorMessage(name);
    }

    protected override ValidationResult IsValid(object value, ValidationContext validationContext)
    {
        return base.IsValid(value, validationContext);
    }

}
Run Code Online (Sandbox Code Playgroud)

一旦在我的模型上使用,我期待正常的结果,就像field is required我还没有定制它,只是调用基本方法.

这似乎没有按预期工作,只是绕过了客户端和服务器端的要求.

这样做的目的是将从db中提取的验证消息添加到ErrorMessage属性中.

c# .net-core asp.net-core asp.net-core-1.1

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

有条件地单独禁用 Serilog 接收器

我的 .net core 应用程序基本配置上有 Serilog,如下所示:-

Log.Logger = new LoggerConfiguration()
        .ReadFrom.Configuration(Configuration)
        .Enrich.FromLogContext()
        .WriteTo.File(@"./logs/log-.log", rollingInterval: RollingInterval.Day, outputTemplate: LOG_TEMPLATE)
        .WriteTo.Console(outputTemplate: LOG_TEMPLATE, theme: AnsiConsoleTheme.Literate)
        .WriteTo.SomeOtherLog()
        .CreateLogger();
Run Code Online (Sandbox Code Playgroud)

现在假设我希望根据条件写入 SomeOtherLog。人们会怎样做呢?

就像是

if(conditon)
.WriteTo.SomeOtherLog()
Run Code Online (Sandbox Code Playgroud)

c# serilog .net-core

6
推荐指数
2
解决办法
4875
查看次数

如果用户使用Google登录,则ASP.NET Core Identity 2.0 SignoutAsync不会注销用户

我有Asp.net核心身份版本2.0设置和运行.我发现,_signinManager.SignoutAsync一旦用户登录Google ,就无法注销用户.当我回到我的登录方法时,它只显示用户登录时其Claim对象仍然完好无损.

代码非常简单,如下所示

[AllowAnonymous]
public ActionResult TestGoogle()
{
    var redirectUrl = Url.Action(nameof(ExternalCallback), "Account", new { ReturnUrl = "" });
    var properties = _signInManager.ConfigureExternalAuthenticationProperties("Google", redirectUrl);
    return Challenge(properties, "Google");
}


public async Task<IActionResult> LogOff()
{
    await _signInManager.SignOutAsync();
    return RedirectToAction(nameof(HomeController.Index), "Home");
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core asp.net-core-identity asp.net-core-2.0

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

从通用列表中删除项目

我试图使用RemoveAt从通用列表中删除项目.奇怪的是,在使用调试器时,我可以看到我的项目已被删除,但在将其传递给视图时,删除的项目正在显示,但最后一项已被删除.

代码看起来像这样

public ActionResult(MyModel model, int[] removeitems)
{
 //model.ListItems has 10 items
 //Incoming removeitems has 0 as the first item to remove as a test
foreach(int item in removeitems)
{
 model.ListItems.RemoveAt(item);
}
 //by this time debugger shows that item 0 has in fact been removed and no longer exists in the list
 return View(model);
 //after the view is rendered it shows item 0 is still there but 10 has been removed
}
Run Code Online (Sandbox Code Playgroud)

我知道我可以通过另一种方式将项目复制到另一个列表等,但所有测试显示上面的代码确实删除了第一个项目,但视图没有反映这一点.

有任何想法吗?

c# asp.net asp.net-mvc

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

C#日期解析非标准日期格式

从 Web 服务获取一个奇怪的日期格式,我想知道如何将其解析为正常的日期时间。

服务结果:01-05T09:55MM-dd 时间

由于此字符串没有年份,因此在DateTime.Parse.

任何想法如何在不使用字符串函数操作它的情况下将其获取到当前年份?

c# datetime datetime-format

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