小编ame*_*els的帖子

Github 拉取请求 - 等待报告状态

我有一个拉取请求,在 VSTS 上传递了构建,但是无论我尝试触发构建多少次,另一个检查“预期 - 等待报告状态”都不会成功。我有许多其他拉取请求,没有任何问题。

我不知道如何解决这个问题,如何调试?没有比这更具体的信息: 在此处输入图片说明

我应该先检查哪里来解决这个问题?

github

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

如何在.net core 2.0中删除x-powered-by标头

我试图使用这个中间件:

public class SecurityHeadersMiddleware
{
    private readonly RequestDelegate next;

    public SecurityHeadersMiddleware(RequestDelegate next)
    {
        this.next = next;
    }

    public async Task Invoke(HttpContext context)
    {
        context.Response.OnStarting(state =>
        {
            var ctx = (HttpContext)state;

            if (!ctx.Response.Headers.ContainsKey("Arr-Disable-Session-Affinity"))
            {
                ctx.Response.Headers.Add("Arr-Disable-Session-Affinity", "True"); // Disables the Azure ARRAffinity cookie
            }

            if (ctx.Response.Headers.ContainsKey("Server"))
            {
                ctx.Response.Headers.Remove("Server"); // For security reasons
            }

            if (ctx.Response.Headers.ContainsKey("x-powered-by") || ctx.Response.Headers.ContainsKey("X-Powered-By"))
            {
                ctx.Response.Headers.Remove("x-powered-by");
                ctx.Response.Headers.Remove("X-Powered-By");
            }

            if (!ctx.Response.Headers.ContainsKey("X-Frame-Options"))
            {
                ctx.Response.Headers.Add("X-Frame-Options", "DENY");
            }

            return Task.FromResult(0);
        }, context);

        await next(context);
    }
}
Run Code Online (Sandbox Code Playgroud)

x-powered-by仍然存在于响应标题中,表示asp.net

c# security azure

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

依赖注入统一 - 条件解析

有条件的解决是目前我​​还不了解的最后一件事.

让我们说我们有一个界面IAuthenticate:

public interface IAuthenticate{
    bool Login(string user, string pass);
}
Run Code Online (Sandbox Code Playgroud)

现在我有两种类型的身份验证.

Twitter认证

public class TwitterAuth : IAuthenticate
{
  bool Login(string user, string pass)
{
   //connect to twitter api
}

}
Run Code Online (Sandbox Code Playgroud)

Facebook Auth

public class FacebookAuth: IAuthenticate
{
  bool Login(string user, string pass)
{
   //connect to fb api
}

}
Run Code Online (Sandbox Code Playgroud)

在unity配置中注册类型:

unityContainer.RegisterType<IAuthenticate, TwitterAuth>();
unityContainer.RegisterType<IAuthenticate, FacebookAuth>();
Run Code Online (Sandbox Code Playgroud)

在我们的控制器中通过DI注入对象:

private readonly IAuthenticate _authenticate;

public AuthenticateController(IAuthenticate authenticate)
{
    _authenticate = authenticate;
}



// login with twitter
public virtual ActionResult Twitter(string user, string …
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection inversion-of-control unity-container

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

如何在vscode中使用TFS时排除文件夹?

我在VS代码中使用Visual Studio Team Services扩展来签入.https://marketplace.visualstudio.com/items?itemName = ms-vsts.team

我现在正在尝试检查角度项目的更改,但我很烦恼排除了来自node_modules的16000个文件: 在此输入图像描述

如何从源代码管理中排除这些文件?在Visual Studio中我使用.tfignore文件,vscode怎么样?

c# tfvc visual-studio-code

10
推荐指数
1
解决办法
1974
查看次数

Angular2反应形式显示基于验证失败条件的错误消息

我想提一下,我使用单独的通用组件,以显示错误,所以我不是直接将它们放在html中以避免重复,所以我不能直接在模板中链接和硬编码条件.

我有这个字段和两个验证:

this.username = new FormControl('', [ Validators.minLength(5), Validators.required ]); 
Run Code Online (Sandbox Code Playgroud)

如何为每个验证显示验证错误消息?假设我想在提交字段中显示任何内容时显示两个错误:
"最小长度为5"
"字段是必需的"

然后,如果你把东西放进去,它应该只显示:
"最小长度为5"

这是一个例子,但是,我的现实生活中的例子,比较两个电子邮件字段,如果它们是相同的,因此,如果邮件是不正确的是应该显示:
"电子邮件是不正确的"
"电子邮件是不一样的第一封电子邮件场"

因此,如果电子邮件是正确的并且电子邮件不相同,则只应显示:
"电子邮件与第一个电子邮件字段不同"

我如果没有通过验证的工作,但我不知道如何分开显示,如果一个验证通过,另一个没有,因为我要好好追加的真正原因失败的原因,而不是把两者一些通用的原因.

完整示例:

错误显示组件:

import { Component, OnInit, Input } from '@angular/core';

@Component({
  selector: 'app-field-error-display',
  templateUrl: './field.error.display.component.html',
  styleUrls: ['./field.error.display.component.css']
})
export class FieldErrorDisplayComponent
{
    @Input() errorMsg: string;
    @Input() displayError: boolean;
}
Run Code Online (Sandbox Code Playgroud)

组件html:

<div *ngIf="displayError" >
  <small>{{errorMsg}}</small>
</div>
Run Code Online (Sandbox Code Playgroud)

在Register.html中使用erorr显示:

<form [formGroup]="_form" (ngSubmit)="register()">
<h4>Create a new account</h4>
<div class="form-group">
  <label for="email">Email Address</label>
  <input class="form-control" name="email" formControlName="email" />
  <app-field-error-display [displayError]="formValidationService.IsFieldValid(_form,'email')" errorMsg="Please insert correct email"></app-field-error-display> …
Run Code Online (Sandbox Code Playgroud)

validation angular angular-reactive-forms

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

Automapper和StructureMap正确的实例注册.net核心

目前,这是我使用StructureMap连接自动映射器的IMapper实例的方式.

public class DefaultRegistry : Registry
    {
        public DefaultRegistry()
        {
            Scan(o =>
            {
                o.AddAllTypesOf<Profile>();
            });

            For<IMapper>().Use(() => Mapper.Instance);
        }
    }
Run Code Online (Sandbox Code Playgroud)

在网络核心创业中:

    var container = new Container(new DefaultRegistry());
    container.Populate(services);

    services.AddAutoMapper(cfg => cfg.ConstructServicesUsing(container.GetInstance));
    Mapper.AssertConfigurationIsValid();
Run Code Online (Sandbox Code Playgroud)

由于Mapper.Instance创建静态,如何将其注册为实例?或者使用StructureMap连接它的正确方法是什么?

c# structuremap automapper

7
推荐指数
0
解决办法
668
查看次数

如何在Automapper中映射嵌套的子对象属性

我有当前的地图:

CreateMap<Article, ArticleModel>()
    .ForMember(dest => dest.BaseContentItem, opts => opts.MapFrom(src => src.BaseContentItem))
    .ForMember(dest => dest.BaseContentItem.TopicTag, opts => opts.MapFrom(src => src.BaseContentItem.TopicTag))
    .ForMember(dest => dest.MainImage, opts => opts.MapFrom(src => src.MainImage))
    .ReverseMap();
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

System.ArgumentException:'Expression'dest => dest.BaseContentItem.TopicTag'必须解析为顶级成员而不是任何子对象的属性.请改用子类型或AfterMap选项上的自定义解析器.

我该如何映射?

c# automapper

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

Angular2如何获取反应形式的输入类型值

我正在构建有角度的反应形式.我有简单的单选按钮,性别名称:

this._form = this._formBuilder.group({
            gender: ['', Validators.required]
        });
Run Code Online (Sandbox Code Playgroud)

模板:

            <div class="form-group">
                <h4>What is your gender?</h4>
                <div class="form-group">
                    <label class="custom-control custom-radio">
                        <input value="male" name="gender" type="radio" class="custom-control-input" formControlName="gender">
                        <span class="custom-control-indicator"></span>
                        <span class="custom-control-description">Male</span>
                    </label>
                    <label class="custom-control custom-radio">
                        <input value="female" name="gender" type="radio" class="custom-control-input" formControlName="gender">
                        <span class="custom-control-indicator"></span>
                        <span class="custom-control-description">Female</span>
                    </label>
                    <app-field-error-display [displayError]="formValidationService.IsFieldInvalid(_form,'gender','required')" errorMsg="Field is required"></app-field-error-display>
                </div>
            </div>
Run Code Online (Sandbox Code Playgroud)

我可以按名称访问控制字段,如下所示:

public GetControl(form: FormGroup, field: string){
        return form.get(field);
    }
Run Code Online (Sandbox Code Playgroud)

基于此,如何访问type ="radio"的属性值?我想知道输入控件是否是无线电类型.

angular angular-reactive-forms

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

VSTS构建-在发布阶段替换Angular4环境变量

目前,我在Angular4中拥有三种不同的环境:

  • 环境
  • 环境调试
  • 环境释放

在此处输入图片说明

现在,在vsts构建管道中,我设置了多重配置,其中一个定义为调试和发布准备了工件:
在此处输入图片说明

在运行npm installnpm run(调试或发布)之前,我正在使用“ 替换令牌 ”任务替换每个调试和发布环境的变量,然后运行webpack打包用于调试或发布环境的文件。

我看到Release中有一个替换变量的选项,您可以在其中替换.json文件中的变量(例如appsettings.json): 在此处输入图片说明

但是问题是当webpack将源代码打包到一个bundle.js中时,我想我不能使用release来替换环境变量吗?我可以吗?

因此,我要实现的是将调试和发布版本分离。这很简单,我只是为调试和发布重新创建了单独的定义,其中我仅在每个环境中替换变量。第二阶段是实际上从构建管道中删除“替换令牌”任务,并使用“发布变量”部分替换在“发布”中设置的每个环境的变量。webpack在js中构建包后,Angular怎么可能?

c# azure azure-devops angular

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

允许一个人一次使用帐户的可重复使用方式

我创建了一个功能,可以防止同时为一个用户名进行多次登录,我在这样的操作中调用它:

        int userId = (int)WebSecurity.CurrentUserId;

        if ((this.Session.SessionID != dba.getSessionId(userId)) || dba.getSessionId(userId) == null)
        {
            WebSecurity.Logout();
            return RedirectToAction("Index", "Home");
        }
Run Code Online (Sandbox Code Playgroud)

所以关键是每次用户登录时我都会将他的sessionID保存到数据库字段中.因此,如果具有相同用户名的某人登录已使用相同用户名登录的某人,则会使用此新会话覆盖该数据库字段.如果DB中的sessionID与登录用户的当前会话ID不同,则将其记录下来.

有可能将这部分代码放在一个地方,还是我必须把它放在我的应用程序中的每一个Action中?

我试过Global.asax:

void Application_BeginRequest(object sender, EventArgs e)
    {
        if (Session["ID"] != null)
        {
            int userId = Convert.ToInt32(Session["ID"]);
            if ((this.Session.SessionID != db.getSessionId(userId)) || db.getSessionId(userId) == null)
            {
                WebSecurity.Logout();
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

但是我不能在这里使用Session,也不能使用WebSecurity类,如果我这样做:

    void Application_BeginRequest(object sender, EventArgs e)
    {
        int userId = (int)WebSecurity.CurrentUserId;

        if ((this.Session.SessionID != db.getSessionId(userId)) || db.getSessionId(userId) == null)
        {
            WebSecurity.Logout();
            Response.RedirectToRoute("Default");                
        }
    }
Run Code Online (Sandbox Code Playgroud)

因为我得到null引用异常.

编辑

我用过这个:

    void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext) …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc

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