小编Bon*_*omi的帖子

检查打字稿中通用参数的类型

我正在使用打字稿在反应应用程序中工作。其中一个函数在其中一个变量中接收泛型类型。

如何检查变量的类型 T?这可能吗?

MyFunction<T>(newValues: Array<T>) {
    if (typeof T === "string") {
        // do some stuff
    }
}
Run Code Online (Sandbox Code Playgroud)

typescript

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

未捕获错误:无法分配给引用或>变量!> at _AstToIrVisitor.visitPropertyWrite

我跟随angular.io网站的一个例子,用一个输入创建一个角形的表单,但我遇到了一个错误:

compiler.js:26390未捕获错误:无法分配给引用或变量!在PropertyWrite.visit的_AstToIrVisitor.visitPropertyWrite(webpack-internal:///./node_modules/@angular/compiler/esm5/compiler.js:26611:23)(webpack-internal:///./node_modules/@angular/编译器/ esm5/compiler.js:4900:24)在eval上的convertActionBinding(webpack-internal:///./node_modules/@angular/compiler/esm5/compiler.js:26035:45)(webpack-internal:// /./node_modules/@angular/compiler/esm5/compiler.js:28635:22)在ViewBuilder._createElementHandleEventFn(webpack-internal:///./ node_modules/.js:28631:18)在eval(webpack-internal://)的节点.(匿名函数)(webpack-internal:///./node_modules/@angular/compiler/esm5/compiler.js:28050:27) /./node_modules/@angular/compiler/esm5/compiler.js:28576:22)位于ViewBuilder._createNodeExpressions的Array.map()(webpack-internal:///./ node_modules/@ angular/compiler/esm5/compiler的.js:28575:56)

我做的唯一更改是将"名称"重命名为"用户名".

dashboard.component.ts

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

@Component({
  selector: 'app-dashboard',
  templateUrl: './dashboard.component.html',
  styleUrls: ['./dashboard.component.css']
})
export class DashboardComponent implements OnInit {

  username: string;
  submitted = false;

  constructor() { 
  }

  ngOnInit() {
  }

  onSubmit() { this.submitted = true; }

}
Run Code Online (Sandbox Code Playgroud)

dashboard.component.html

<div class="row justify-content-md-center">
    <div class="col col-lg-12">
      <form (ngSubmit)="onSubmit()" #usernameForm="ngForm" >
        <div class="form-group">
          <label for="username">Name</label>                    

          <input type="text" class="form-control" id="name"
          required
          [(ngModel)]="username" name="name"
          #username="ngModel">

          <div [hidden]="username.valid || username.pristine"
              class="alert alert-danger">
            Name is …
Run Code Online (Sandbox Code Playgroud)

typescript angular

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

使用剃刀禁用输入元素

我需要在其值等于"*"时动态禁用输入.如何使用MVC Razor实现这一目标?

    @Html.TextBoxFor(m => m.Digits[0], new { @class = "form-control input-lg label_16", @placeholder = 
"1st", (Model.Digits[0] == "*" ? "disabled" : "") })
Run Code Online (Sandbox Code Playgroud)

上面的代码没有编译这可能吗?

html c# asp.net-mvc razor

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

如何在app.config中指定类的类型?

我试图了解如何在app.config中引用一个类.在这种情况下,我想在app.config中配置和microsoft unity扩展

<extension type="?, ?" />
Run Code Online (Sandbox Code Playgroud)

type="assemblyName, namespace.class"吗?

c# app-config unity-container

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

使用 CsvHelper 读取带有可选列的 CSV

我想读取一个包含一些可选列的 CSV 文件,因为我已经使用“?”定义了一个具有可选属性的类。但无法使其发挥作用。

public class MyItem
{
    public int Id { get; set; }
    public int? MyValue { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

映射类:

public sealed class MyItemMap : ClassMap<MyItem>
{
    public MyItemMap()
    {
        Map(m => m.Id);
        Map(m => m.MyValue);
    }
}
Run Code Online (Sandbox Code Playgroud)

然后是控制台应用程序:

static void Main(string[] args)
{
    using (var reader = new StreamReader(@"C:\Test2Delete\ConsoleAppCSV\MyItem.csv"))
    using (var csv = new CsvReader(reader))
    {
        csv.Configuration.RegisterClassMap(new MyItemMap());
        csv.Configuration.HeaderValidated = null;
        try
        {
            var records = csv.GetRecords<MyItem>();
            foreach (var r in records)
            {
                Console.WriteLine(r.Id + " …
Run Code Online (Sandbox Code Playgroud)

c# csvhelper

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

Chrome扩展程序webRequest.onBeforeRequest

我正在尝试创建一个扩展来分析在Chrome浏览器上发出的请求,但我不能让它工作.警报永远不会触发.

的manifest.json

{
  "name": "Test",
  "description": "Test",
  "version": "1.0",
  "manifest_version": 2,
  "permissions": ["background", "tabs", "webRequest", "webRequestBlocking", "*://*/*"],    
  "background": {
    "scripts": ["background.js"],
    "persistent": true
  }  
}
Run Code Online (Sandbox Code Playgroud)

background.js

var callback = function(details) {
    alert("hello");
};
var filter = { "*://*/*" };
var opt_extraInfoSpec = [];

chrome.webRequest.onBeforeRequest.addListener(
        callback, filter, opt_extraInfoSpec);
Run Code Online (Sandbox Code Playgroud)

为什么我的警报没有开火?

javascript google-chrome google-chrome-extension

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

在不指定元数据端点的情况下使用 OpenIdConnect

我正在 ASP.Net MVC C# 中开发一个依赖方,它应该在外部身份提供程序中进行身份验证,我使用的是 Microsoft 的 owin 库。我遇到的问题是 Idp 不公开元数据端点,即使我没有在配置中指定它,当我尝试联系 Idp 时也会抛出异常。

[InvalidOperationException:IDX10803:无法创建以从以下位置获取配置:“ https://domain.com/oidc/.well-known/openid-configuration ”。]

我有以下代码片段:

            var options = new OpenIdConnectAuthenticationOptions();
            options.AuthenticationType = authenticationType;            
            options.ClientId = clientConfiguration.ClientID;
            options.ClientSecret = AppSettings.ClientSecret;            
            options.Notifications = new OpenIdConnectAuthenticationNotifications
            {
                SecurityTokenValidated = n => ReceiveValidSecurityToken(n),
                RedirectToIdentityProvider = n => ROSAddProtocolToken(n, clientConfiguration),
                AuthenticationFailed = n => AuthenticationFailed(n),
            };
            options.Authority = AppSettings.Authority;

            options.RedirectUri = clientConfiguration.GetPostLoginRedirectUri(clientConfiguration.CurrentCulture).ToString();
            options.ResponseType = "code";
            options.Scope = AppSettings.Scope;
            options.ClientSecret = clientConfiguration.ClientSecret;

            options.SignInAsAuthenticationType = CookieAuthenticationDefaults.AuthenticationType;
Run Code Online (Sandbox Code Playgroud)

我的问题是,如何指定 MS Owin 库中的所有端点(授权、令牌、用户信息、Jwls)?

Idp 需要以下设置:范围:openid Http 绑定:GET 响应类型:代码令牌端点身份验证方法:client_secret_jwt

c# asp.net owin openid-connect

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

NullInjectorError:没有字符串提供程序

将字符串参数添加到类中的构造函数后,浏览器出现错误:

在此处输入图片说明

我的课程定义如下:

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

import { MatrixComponent } from '../matrix/matrix.component';

@Component({
  selector: 'app-player',
  templateUrl: './player.component.html',
  styleUrls: ['./player.component.css']
})
export class PlayerComponent implements OnInit {
    private userName: string;

    constructor(private name: string) {
        this.userName = name;
        this.discovered = 0;
        this.matrix = new MatrixComponent();
    }

    ngOnInit() {
    }
}
Run Code Online (Sandbox Code Playgroud)

我在另一个类的构造函数中创建对象:

var player1 = new PlayerComponent("Me");
Run Code Online (Sandbox Code Playgroud)

我认为可以在构造函数中传递参数吗?我的代码有什么问题?

typescript angular

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

忽略JWT中的签名

我有一个使用OpenId Connect的Web应用程序.我创建了一个自签名证书,但它仍未由CA签名.如何忽略签名验证?

这是我到目前为止:

SecurityToken validatedToken = null;

var tokenHandler = new JwtSecurityTokenHandler {
    Configuration = new SecurityTokenHandlerConfiguration {
        CertificateValidator = X509CertificateValidator.None
    },
};

TokenValidationParameters validationParams =
    new TokenValidationParameters()
    {
        ValidAudience = ConfigurationManager.AppSettings["Audience"],
        ValidIssuer = ConfigurationManager.AppSettings["Issuer"],
        AudienceValidator = AudienceValidator,
        ValidateAudience = true,
        ValidateIssuer = true
    };

return tokenHandler.ValidateToken(jwtToken, validationParams, out validatedToken);
Run Code Online (Sandbox Code Playgroud)

它抛出以下异常:

IDX10500:签名验证失败.无法解析SecurityKeyIdentifier:'SecurityKeyIdentifier\r \n(\ r \n
IsReadOnly = False,\ r \nCount = 1,\ r \n Clause [0] = System.IdentityModel.Tokens.NamedKeySecurityKeyIdentifierClause\r \n
)\ r \n',\ntoken:'{\"typ \":\"JWT \",\"alg \":\"RS256 \",\"kid \":\"issuer_rsaKey \"}.{\" ISS \":...

.net c# x509certificate jwt

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

css“悬停”在滑块上不起作用

我在使用轨道滑块内的悬停时遇到问题,它根本不起作用。我究竟做错了什么?

这是代码和小提琴: http: //jsfiddle.net/Bonomi/KgndE/

HTML:

<div class="row">
    <div class="large-12">
        <ul data-orbit>
            <li>
                <img src="http://upload.wikimedia.org/wikipedia/commons/a/a7/Saturn-day-earth-smiled-1000x600.png" alt="slide 1"/>
                <div class="orbit-caption">
                Caption 1
                </div>
            </li>            
        </ul>
        <div class="orbit-caption">
        Caption 2
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS:

.orbit-caption:hover {
    background-color: red;
}
Run Code Online (Sandbox Code Playgroud)

提前致谢

html css zurb-foundation orbit

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

向Windows Azure AD添加更多声明

我一直在努力了解AD如何在Azure中运行.我有一个Web应用程序,我想使用WAAD为应用程序提供声明.从我看到的到现在为止,唯一提供的是用户名.有没有办法向Azure AD添加外部声明?

谢谢

azure wif azure-active-directory

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

在Asp.Net MVC应用程序中调用wcf服务

这可能是一个非常基本的问题,但我还没弄清楚如何在mvc应用程序中调用简单的wcf服务.我添加了服务引用,最后我希望使用服务引用名称来调用它,但在解决方案中我找不到它!我究竟做错了什么?

更新25/09/2014

  1. 使用现有模板Visual Studio 2014创建WcfService应用程序
  2. 使用Visual Studio 2014中的现有模板创建MVC 4 Web App
  3. 将WcfService引用添加到MVC应用程序. 在此输入图像描述

控制器代码:

namespace MvcApplication4.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
            ServiceReference1.Service1 srv = new ServiceReference1.Service1();
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

WCF服务代码:

namespace WcfService1
{
    // NOTE: You can …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc wcf

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