小编IT *_*Han的帖子

任务与异步任务

好的,我一直在试图解决这个问题,我已经阅读了一些文章,但没有一篇提供我正在寻找的答案。

我的问题是:为什么Task必须返回 Task 而async Task不必返回?例如:

public override Task TokenEndpoint(OAuthTokenEndpointContext context)
{
    // Code removed for brevity.

    return Task.FromResult<object>(null);
}
Run Code Online (Sandbox Code Playgroud)

正如你在那里看到的,那个方法不是async,所以它必须返回一个任务。

现在,看看这个:

public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
    // Code removed for brevity...
    if(user == null)
    {
        context.SetError("invalid_grant", "username_or_password_incorrect");
        return;
    }

    if(!user.EmailConfirmed)
    {
        context.SetError("invalid_grant", "email_not_confirmed");
        return;
    }

    // Code removed for brevity, no returns down here...
}
Run Code Online (Sandbox Code Playgroud)

它使用async关键字,但不返回任务。这是为什么?我知道这可能是有史以来最愚蠢的问题。但我想知道为什么会这样。

.net c# task

9
推荐指数
2
解决办法
4638
查看次数

调试 ASP.Net Core 2.1 时自动登录

我正在尝试在我构建的 ASP.net core 2.1 应用程序上自动登录以进行调试。

得到错误:

HttpContext 不能为空。

下面的代码位于Startup.cs文件中

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider ServiceProvider)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseStaticFiles();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });

        app.UseCookiePolicy();

        CreateRoles(ServiceProvider).Wait();

        if (env.IsDevelopment())
        {
            DeveloperLogin(ServiceProvider).Wait();
        }
    }


    private async Task DeveloperLogin(IServiceProvider serviceProvider){

        var UserManager = serviceProvider.GetRequiredService<UserManager<User>>();
        var signInManager = serviceProvider.GetRequiredService<SignInManager<User>>();

        var …
Run Code Online (Sandbox Code Playgroud)

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

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

如何禁用生成“exports.__esModule = true;” 和“需要(“lib”);”

例如:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="app">
        {{ message }}
    </div>

    <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js'></script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.js'></script>
    <script src="app.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

应用程序.ts:

import { Vue } from "vue/types/vue";

let vue = new Vue({
    el:"#app",
    data:{
        text:"hello world"
    }
})
Run Code Online (Sandbox Code Playgroud)

cmd后tsc会生成下面的js

"use strict";
exports.__esModule = true;
var vue_1 = require("vue/types/vue");
var vue = new vue_1.Vue({
    el: "#app",
    data: {
        text: "hello world"
    }
});
Run Code Online (Sandbox Code Playgroud)

我的预期

我希望禁用生成“exports.__esModule = true;” …

typescript

4
推荐指数
1
解决办法
5842
查看次数

运行asp.net core api项目时如何在vscode中设置不打开新的Web浏览器选项卡

例如

每次我在 vscode 中键入ctrl + f5ctrl + shift + f5重新运行 asp.net core api 项目时,它都会打开一个新选项卡。

我希望只是重新启动程序without opening new tab

c# asp.net-web-api visual-studio-code asp.net-core

4
推荐指数
1
解决办法
1175
查看次数

如何在不停止.NET5中的IIS应用程序和池的情况下更新ASP.NET Core文件?

每次需要停止IIS应用程序或池来更新

或者系统会显示The action can't be completed becacuse the file is open in w3wp.exe

我希望像asp.net或mvc一样,你不需要停止IIS来更新。


现在我的方式,我drop a file called app_offline.htm (case sensitive) to my application folder. Let IIS auto stop my application then I update it

从这篇文章iis - 如何在不停止 Web 服务器的情况下通过现有/正在运行的站点更新 ASP.NET Core 应用程序?- 堆栈溢出

iis asp.net-core .net-5

4
推荐指数
1
解决办法
2649
查看次数

coalesce(null,'')在oracle中获取null,在SQL Server中获取''

  • Oracle版本:12.1.0.2.0
  • SQL Server版本:2012

我的代码:

select COALESCE (null, '') 
from dual
Run Code Online (Sandbox Code Playgroud)

在Oracle中返回null结果,但是

select COALESCE (null, '')
Run Code Online (Sandbox Code Playgroud)

在SQL Server中返回一个''结果.

为什么这个结果有所不同?

它们是ANSI标准,应该不一样吗?

sql sql-server oracle

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

使用详细记录查询之前的最后一个价格

样本

+---------+------------+----------+------------+
| prdt_no | order_date | quantity | unit_price |
+---------+------------+----------+------------+
| A001    | 2020-01-01 |      100 |         10 |
| A001    | 2020-01-10 |      200 |         10 |
| A001    | 2020-02-01 |      100 |         20 |
| A001    | 2020-02-05 |      100 |         20 |
| A001    | 2020-02-07 |      100 |         20 |
| A001    | 2020-02-10 |      100 |         15 |
| A002    | 2020-01-01 |      100 |         10 |
| A002    | 2020-01-10 | …
Run Code Online (Sandbox Code Playgroud)

sql sql-server

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

C#new Dictionary <string,object>()是IDictionary <object,object>返回false

例:

void Main()
{
    var dic = new Dictionary<string, object>();

    Console.WriteLine(dic is IDictionary<object, object>); //False
    Console.WriteLine(dic is IDictionary<dynamic, dynamic>); //False
    Console.WriteLine(dic is IDictionary<string, object>); //True
}
Run Code Online (Sandbox Code Playgroud)

字符串也不是对象吗?为什么dic is IDictionary<object, object>变得虚假.

c#

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

VS2019:推送到远程存储库时遇到错误:Git 失败,出现致命错误。无法访问

今天,我的 Visual Studio 2019 团队资源管理器 github push 出现以下错误。
我不知道如何解决这个错误。

错误信息 :

Pushing master
Error encountered while pushing to the remote repository: Git failed with a fatal error.
unable to access 'https://github.com/xxxxxxx.git': error setting certificate verify locations:
  CAfile: c:/program files (x86)/microsoft visual studio/2019/community/common7/ide/commonextensions/microsoft/teamfoundation/team explorer/Git/mingw32/bin/curl-ca-bundle.crt
  CApath: none
Pushing to https://github.com/xxxxxxx.git
Run Code Online (Sandbox Code Playgroud)

图像-20200820161839927

图像-20200820161904353

我的 git 版本:

$ git --version
git version 2.17.1.windows.2
Run Code Online (Sandbox Code Playgroud)

我的C:\ProgramData\Git\config

[core]
    symlinks = false
    autocrlf = true
    fscache = true
[color]
    diff = auto
    status = auto
    branch = auto …
Run Code Online (Sandbox Code Playgroud)

git visual-studio-2019

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

'#if DEBUG' 和 '#endif' 如何删除两个标记之间的内容

'#if DEBUG' 和 '#endif' 如何删除两个标记之间的内容

例如:在 SQL 字符串下面期望像 '#if DEBUG' 和 '#endif' 来删除/**if DEBUG**//**endif**/

select
    id
    ,name
    /**if DEBUG**/
    ,test1
    ,test2
    /**endif**/
from table
where sDate >= '2021-01-01'
    /**if DEBUG**/
    and test1 = '123456'
    /**endif**/

Run Code Online (Sandbox Code Playgroud)

预期结果 :

select
    id
    ,name
from table
where sDate >= '2021-01-01'

Run Code Online (Sandbox Code Playgroud)

我试过的

我试过使用正则表达式

  1. (\/\*\*if\sDEBUG\*\*\/)(?<content>)(\/\*\*endif\*\*\/)
  2. (\/\*\*if\sDEBUG\*\*\/)|(\/\/[\w\s\']*)|(\/\*\*endif\*\*\/)

要获取字符串但不起作用,我的代码:

void Main()
{
    var input = @"
select 
    id
    ,name
    /**if DEBUG**/
    ,test1
    ,test2
    /**endif**/
from table
where sDate >= '2021-01-01'
    /**if DEBUG**/
    and test1 = …
Run Code Online (Sandbox Code Playgroud)

c# regex

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

从不同的多列中删除相同的排列

样本数据:

val1,val2
1,1
1,2
1,3
2,1
2,2
2,3
3,1
3,2
3,3
4,1
Run Code Online (Sandbox Code Playgroud)

异常输出:

val1,val2
1,2
1,3
2,3
4,1
Run Code Online (Sandbox Code Playgroud)

逻辑:
删除相同的 val 排列并保留 min val1 数据。
例如:
删除,1,1因为它们是相同的。
删除2,1因为1,2存在...等

数据 SQL 脚本:

val1,val2
1,1
1,2
1,3
2,1
2,2
2,3
3,1
3,2
3,3
4,1
Run Code Online (Sandbox Code Playgroud)

SQL Server 2012 | 数据库<>小提琴

sql sql-server

0
推荐指数
1
解决办法
210
查看次数

ASP.NET Core 3.1在IIS .NET CLR v4.0上运行并且集成托管必须是每个APP的一个池?

我运行多个 asp.net core 3.1 应用程序运行 Windows IIS,系统将显示错误HTTP Error 500.35 - ANCM Multiple In-Process Applications in same Process

对于asp.net mvc来说这是可以的,它可以在同一个池中运行多个应用程序。

编辑:

我读过https://learn.microsoft.com/en-us/aspnet/core/test/troubleshoot-azure-iis?view=aspnetcore-5.0#50035-ancm-multiple-in-process-applications-in-同进程

500.35 ANCM 同一进程中存在多个进程内应用程序 工作进程无法在同一进程中运行多个进程内应用程序。
要修复此错误,请在单独的 IIS 应用程序池中运行应用程序。

看起来每个APP都必须有一个池......

iis asp.net-core asp.net-core-3.1

0
推荐指数
1
解决办法
4201
查看次数