小编Cod*_*und的帖子

虚拟成员在构造函数中调用

我从ReSharper收到一条关于从我的对象构造函数调用虚拟成员的警告.

为什么不做这件事?

c# resharper constructor warnings virtual-functions

1270
推荐指数
11
解决办法
17万
查看次数

如何还原已经推送到远程分支的合并提交?

git revert <commit_hash>单独行不通.-m必须指定,我对它很困惑.

以前有人经历过吗?

git

827
推荐指数
12
解决办法
60万
查看次数

在单元测试中设置HttpContext.Current.Session

我有一个Web服务,我正在尝试进行单元测试.在服务中,它从HttpContext类似物中提取了几个值,因此:

 m_password = (string)HttpContext.Current.Session["CustomerId"];
 m_userID = (string)HttpContext.Current.Session["CustomerUrl"];
Run Code Online (Sandbox Code Playgroud)

在单元测试中,我使用简单的工作者请求创建上下文,如下所示:

SimpleWorkerRequest request = new SimpleWorkerRequest("", "", "", null, new StringWriter());
HttpContext context = new HttpContext(request);
HttpContext.Current = context;
Run Code Online (Sandbox Code Playgroud)

但是,每当我尝试设置值时 HttpContext.Current.Session

HttpContext.Current.Session["CustomerId"] = "customer1";
HttpContext.Current.Session["CustomerUrl"] = "customer1Url";
Run Code Online (Sandbox Code Playgroud)

我得到null引用异常,表示HttpContext.Current.Session为null.

有没有办法在单元测试中初始化当前会话?

c# unit-testing web-services httpcontext

180
推荐指数
8
解决办法
15万
查看次数

docker登录未知速记标志:'e'

我刚刚更新了我的docker版本并找到了该命令

aws ecr get-login
Run Code Online (Sandbox Code Playgroud)

不再工作了.得到错误:

未知的速记标志:'e'在-e`中.似乎docker不再支持-e标志了.

有没有办法来解决这个问题?

已安装的版本:

aws-cli/1.11.111 Python/2.7.10 Darwin/16.6.0 botocore/1.5.74

Docker version 17.06.0-ce-rc5, build b7e4173
Run Code Online (Sandbox Code Playgroud)

amazon-ecs docker

116
推荐指数
3
解决办法
2万
查看次数

ASP.Net Core 2.1中的身份:自定义AccountController

我已经安装了ASP.NET Core 2.1,但即使我已经创建了一个新的ASP.NET Core Web Application使用ASP.NET Core 2.1Individual User AccountsStore user accounts in-app我无法找到的AccountController或意见.

我仍然可以注册和登录没有问题,但我找不到它的代码,它存在于2.0.

在此输入图像描述

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

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

MVC3验证 - 从组中需要一个

给定以下viewmodel:

public class SomeViewModel
{
  public bool IsA { get; set; }
  public bool IsB { get; set; }
  public bool IsC { get; set; } 
  //... other properties
}
Run Code Online (Sandbox Code Playgroud)

我希望创建一个自定义属性,验证至少有一个可用属性为true.我设想能够将属性附加到属性并分配组名称,如下所示:

public class SomeViewModel
{
  [RequireAtLeastOneOfGroup("Group1")]
  public bool IsA { get; set; }

  [RequireAtLeastOneOfGroup("Group1")]
  public bool IsB { get; set; }

  [RequireAtLeastOneOfGroup("Group1")]
  public bool IsC { get; set; } 

  //... other properties

  [RequireAtLeastOneOfGroup("Group2")]
  public bool IsY { get; set; }

  [RequireAtLeastOneOfGroup("Group2")]
  public bool IsZ { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我希望在表单提交之前在客户端验证表单更改中的值,这就是为什么我更愿意在可能的情况下避免使用类级别属性. …

asp.net-mvc jquery-validate unobtrusive-validation asp.net-mvc-3

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

仅在第一个Web请求时抛出Ninject.ActivationException(WebAPI 2,OWIN 3,Ninject 3)

我正在尝试创建一个"准系统"Web API项目,该项目使用OWIN中间件,Ninject Depencency Injection,最终将在IIS中托管.我按照文章"与ASP.NET Web.API2,OWIN和Ninject建立联系"中的说明进行了操作:http://www.alexzaitzev.pro/2014/11/webapi2-owin-and-ninject.html,除了我使用了一个空的Web应用程序项目,并且在创建项目时没有勾选"包含Web API引用和文件夹".

当我启动新API并发出页面请求时,我会Ninject.ActivationException抛出以下内容:

Server Error in '/' Application.

Error activating HttpConfiguration
More than one matching bindings are available.
Matching bindings:
 1) binding from HttpConfiguration to method
 2) binding from HttpConfiguration to constant value
Activation path:
 1) Request for HttpConfiguration

Suggestions:
 1) Ensure that you have defined a binding for HttpConfiguration only once.
Run Code Online (Sandbox Code Playgroud)

刷新浏览器时,此异常消失了.我真的不明白是什么导致了这个异常.从我的观点来看,在OWIN环境和Ninject中对WebAPI缺乏经验,很难知道问题出在哪里.与Ninject一起......?它在OWIN ......?是在WebAPI ......?

这是我的Startup.cs文件的内容:

using System.Web.Http;
using LHD.API_2;
using Microsoft.Owin;
using Microsoft.Owin.Security.OAuth;
using Ninject.Web.Common.OwinHost;
using Ninject.Web.WebApi.OwinHost;
using Owin; …
Run Code Online (Sandbox Code Playgroud)

ninject asp.net-web-api owin

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

如何在EF Core 2.0中显示基础SQL查询?

在这个" .NET Core 2.0 Released! "视频结束时的3:15 ,Diego Vega展示了Entity Framework Core 2.0中的新功能演示.作为其中一部分,控制台应用程序中显示了底层SQL的转储.

在此输入图像描述

我在Stack Overflow上看到很多答案,建议人们使用SQL分析器来查看底层查询.但现在我很好奇:你怎么能做Diego Vega所做的事情,并在应用程序中显示查询?

c# entity-framework-core

29
推荐指数
10
解决办法
2万
查看次数

Jenkins管道在Windows上无法运行"无法运行程序nohup"

我有Windows 10,我想在Jenkins管道中使用bash为Ubuntu for windows执行Jen命令中的sh命令,但它不起作用

我的Jenkins管道中有以下阶段:

stage('sh how to') {
        steps {
            sh 'ls -l'
        }
    }
Run Code Online (Sandbox Code Playgroud)

错误消息是:

[C:\ Program Files(x86)\ Jenkins\workspace\pipelineascode]运行shell脚本无法运行程序"nohup"(在目录"C:\ Program Files(x86)\ Jenkins\workspace\pipelineascode"中):CreateProcess error = 2 ,Lefichierspécifiéestintrouvable

我尝试用更改Jenkins参数 - > shell可执行文件

C:\ WINDOWS\SYSTEM32\bash.exe

但同样的错误......

如何使用Windows 10的bash运行sh脚本?

bash jenkins windows-10 jenkins-pipeline

27
推荐指数
7
解决办法
3万
查看次数

.NET Core Identity作为UI取消注册

我想取消.NET Core 2.1 + Identity中的'Register'选项作为UI应用程序.

我当然可以简单地从页面上删除按钮,问题是 - 这样安全吗?

如果不是我的其他选择?我应该使用脚手架来生成注册码然后在那里禁用它吗?

(同样适用于SetPassword等)

谢谢

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

23
推荐指数
3
解决办法
2487
查看次数