小编joh*_*y 5的帖子

CORS:凭证模式是'包含'

是的,我知道你在想什么 - 还有另一个CORS问题,但这次我很难过.

所以要开始,实际的错误信息:

XMLHttpRequest无法加载http://localhost/Foo.API/token.当请求的凭据模式为"include"时,响应中"Access-Control-Allow-Origin"标头的值不能是通配符"*".因此不允许来源' http:// localhost:5000 '访问.XMLHttpRequest发起的请求的凭据模式由withCredentials属性控制.

我不确定凭证模式的含义是'包含'

所以当我在邮递员中执行请求时,我没有遇到这样的错误:

在此输入图像描述

但是当我通过我的angularjs网络应用程序访问相同的请求时,我被这个错误所困扰.这是我的angualrjs请求/回复.你会看到响应OK 200,但我仍然收到CORS错误:

小提琴请求和响应:

下图演示了Web前端到API的请求和响应

提琴手

所以基于我在网上阅读的所有其他帖子,看起来我做的是正确的,这就是为什么我无法理解错误.最后,这是我在angualrjs(登录工厂)中使用的代码:

在此输入图像描述

API中的CORS实现 - 参考目的:

方法1使用:

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        EnableCrossSiteRequests(config);
    }

    private static void EnableCrossSiteRequests(HttpConfiguration config)
    {
        var cors = new EnableCorsAttribute("*", "*", "*")
        {
            SupportsCredentials = true
        };
        config.EnableCors(cors);
    }
}
Run Code Online (Sandbox Code Playgroud)

方法2使用:

public void Configuration(IAppBuilder app)
{
    HttpConfiguration config = new HttpConfiguration(); …
Run Code Online (Sandbox Code Playgroud)

javascript c# cors angularjs asp.net-web-api2

71
推荐指数
4
解决办法
8万
查看次数

.NET Core Identity Server 4身份验证VS身份验证

我试图了解在ASP.NET Core中进行身份验证的正确方法.我看过几个资源(其中大部分都已过时).

有些人提供了使用基于云的解决方案(如Azure AD)或使用IdentityServer4并托管我自己的令牌服务器的替代解决方案.

在早期版本的.Net中,一种更简单的身份验证形式是创建自定义Iprinciple并在其中存储其他身份验证用户数据.

public interface ICustomPrincipal : System.Security.Principal.IPrincipal
{
    string FirstName { get; set; }

    string LastName { get; set; }
}

public class CustomPrincipal : ICustomPrincipal
{
    public IIdentity Identity { get; private set; }

    public CustomPrincipal(string username)
    {
        this.Identity = new GenericIdentity(username);
    }

    public bool IsInRole(string role)
    {
        return Identity != null && Identity.IsAuthenticated && 
           !string.IsNullOrWhiteSpace(role) && Roles.IsUserInRole(Identity.Name, role);
    }

    public string FirstName { get; set; }

    public string LastName { get; set; …
Run Code Online (Sandbox Code Playgroud)

c# asp.net authentication openid-connect asp.net-core

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

Angular 2使指令需要@Input

在Angular 1中,我们可以创建一个指令属性.我们如何使用@Input在Angular 2中做到这一点?文档没有提到它.

例如.

Component({
    selector: 'my-dir',
    template: '<div></div>'
})
export class MyComponent {
  @Input() a:number; // Make this a required attribute. Throw an exception if it doesnt exist
  @Input() b:number;

  constructor(){

  }
}
Run Code Online (Sandbox Code Playgroud)

angular2-directives angular

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

JQuery DataTables - 行分组,求和,可折叠,导出

我一直在使用JQuery DataTables.这是我第一次使用行分组.我找到了一个我想要开始的好例子.- 分组

  1. 如何<td>在分组行中添加额外内容?如果我想在该分组行上显示分组工资的总和,该怎么办?现在,看起来您只能显示该组的名称.

在此输入图像描述

  1. 我可以让这些行像他们在这里这里一样可折叠吗?看起来这是一个与原始分组代码不同的插件. 这种外观是我的偏好,但使用子行似乎与分组不一样.

附加信息

我将从Ajax源返回数据.

更新1

因此,我构建了一个包含行分组的表,并找到了如何总结列的示例.我正在将该值插入<td>该组行中.我现在需要的是如何将总和数量分解为组而不是整个列的总和.我需要帮助.

"drawCallback": function (settings) {
    var api = this.api(), data;
    var rows = api.rows({ page: 'current' }).nodes();
    var last = null;

    //Calculates the total of the column
    var total = api
        .column(5)  //the salary column
        .data()
        .reduce(function (a, b) {
            return a + b;
        }, 0);

    //Groups the Office column
    api.column(2, { page: 'current' }).data().each(function (group, i) {
        if (last …
Run Code Online (Sandbox Code Playgroud)

javascript jquery datatables

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

如何从content-disposition获取文件名

我下载文件作为ajax的响应.如何从内容处理中获取文件名和文件类型,并为其显示缩略图.我有很多搜索结果,但找不到正确的方法.

$(".download_btn").click(function () {
    var uiid = $(this).data("id2");

    $.ajax({
        url: "http://localhost:8080/prj/" + data + "/" + uiid + "/getfile",
        type: "GET",
        error: function (jqXHR, textStatus, errorThrown) {
            console.log(textStatus, errorThrown);
        },
        success: function (response, status, xhr) 
        {
            var header = xhr.getResponseHeader('Content-Disposition');
            console.log(header);     
        }
    });
Run Code Online (Sandbox Code Playgroud)

控制台输出:inline; filename=demo3.png

javascript ajax filenames file-type content-disposition

33
推荐指数
5
解决办法
4万
查看次数

@viewChild不工作 - 无法读取未定义的属性nativeElement

我正在尝试访问本机元素,以便在单击另一个元素时专注于它(非常类似于html属性"for" - 因为不能在此类型的元素上使用.

但是我得到错误:

TypeError:无法读取未定义的属性"nativeElement"

我尝试console.log中的nativeElement,ngAfterViewInit()以便它被加载,但它仍然会抛出错误.

我还在click事件处理程序中访问nativeElement,这样我可以在单击另一个元素时聚焦该元素 - 这可能是什么在混淆它,因为它在视图加载之前编译?

例如:

ngAfterViewInit() {
    console.log(this.keywordsInput.nativeElement); // throws an error
}

focusKeywordsInput(){
    this.keywordsInput.nativeElement.focus();
}
Run Code Online (Sandbox Code Playgroud)

完整代码:

正在使用的html模板的相关部分:

<div id="keywords-button" class="form-group" (click)="focusKeywordsInput()">
    <input formControlName="keywords" id="keywords-input" placeholder="KEYWORDS (optional)"/>
    <div class="form-control-icon" id="keywords-icon"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

component.ts:

import { Component, OnInit, AfterViewInit, ViewChild, ElementRef } from '@angular/core';
import {  REACTIVE_FORM_DIRECTIVES, 
          FormGroup, 
          FormBuilder, 
          Validators,
          ControlValueAccessor
        } from '@angular/forms';
import { NumberPickerComponent } from './number-picker.component';
import { DistanceUnitsComponent } from './distance-units.component';
import { MapDemoComponent } from '../shared/map-demo.component';
import { AreaComponent …
Run Code Online (Sandbox Code Playgroud)

viewchild angular

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

实体框架中的嵌套查询

我收到以下异常:

不支持嵌套查询.Operation1 ='案例'Operation2 ='收集'

有了这个查询

var Games = context.Games.Select(a => new GameModel
{
     Members = (a.Type == 1 ? (a.UsersInGames.Where(b => b.GameID == a.ID && b.StatusID == 1).Select(c => new Member
     {
         ID = c.UserID,
         email = c.UserInfo.EmailAddress,
         screenName = c.UserInfo.ScreenName
     })) :   
    (a.Teams.Where(b => b.GameID == a.ID).SelectMany(b => b.UsersInTeams.Where(c => c.StatusID == 1)).Select(d => new Member
    {
        ID = d.UserID,
        email = d.UserInfo.EmailAddress,
        screenName = d.UserInfo.ScreenName
    )))
})
Run Code Online (Sandbox Code Playgroud)

当我在选择成员时不包括条件时,查询工作正常.有没有办法可以在查询中执行条件?

c# linq entity-framework

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

Visual Studio 2017错误 - 无法连接到运行时进程

每当我尝试从visual studio调试我的项目时,我都会收到此错误.

我尝试将这些设置添加到launchSettings.json但仍然没有区别.

"protocol":"legacy","runtimeArgs":[" - debug = 5858"],"restart":true,"port":5858,

在此输入图像描述

我在这里做错了什么.有什么建议可以解决这个问题吗?

c# visual-studio-2017

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

.Net Core 2.1 - 无法访问已处置的对象.对象名称:'IServiceProvider'

我刚刚将.NET Core 2.0迁移到.NET Core 2.1.一切都很顺利,但是当我尝试登录时,我得到了以下错误:

  • $ exception {System.ObjectDisposedException:无法访问已处置的对象.对象名称:'IServiceProvider'.

这发生在这段代码中:

public class AppContractResolver : DefaultContractResolver
{

    private readonly IServiceProvider _services;

    public AppContractResolver(IServiceProvider services)
    {
        _services = services;
    }

    protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
    {
        var httpContextAccessor = _services.GetService<IHttpContextAccessor>();
        var user = httpContextAccessor.HttpContext.User;

        List<JsonProperty> properies = base.CreateProperties(type, memberSerialization).ToList();

        properies = FilterOneClaimGranted(type, properies, user);

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

它出现在这一行:

var httpContextAccessor = _services.GetService<IHttpContextAccessor>();
Run Code Online (Sandbox Code Playgroud)

这确实适用于.NET Core 2.0

我已经尝试添加HttpContextAccessor到我的启动,但这不起作用.

那么,我该如何解决这个问题呢?

如果您需要更多代码,请与我们联系.我很乐意提供更多,但我不知道你可能需要什么或不需要什么,所以我没有添加很多代码.

编辑

我已经添加services.AddHttpContextAccessor();到我的创业公司,但这似乎不起作用.仍然得到错误.

编辑2:

完整的堆栈跟踪:

- $exception    {System.ObjectDisposedException: Cannot access …
Run Code Online (Sandbox Code Playgroud)

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

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

使用webAPI承载令牌进行SignalR认证

+我使用这个解决方案来实现使用ASP.NET Web API 2,Owin和Identity的基于令牌的身份验证......效果非常好.我使用这个其他解决方案,这通过传递承载令牌通过连接字符串来实现signalR集线器授权和身份验证,但似乎要么承载令牌没有,或者某处其他地方出错,这就是为什么我在这里寻求帮助. ..这些是我的代码... QueryStringBearerAuthorizeAttribute:这是负责验证的类

using ImpAuth.Entities;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.OAuth;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using System.Web;

namespace ImpAuth.Providers
{
    using System.Security.Claims;
    using Microsoft.AspNet.SignalR;
    using Microsoft.AspNet.SignalR.Hubs;
    using Microsoft.AspNet.SignalR.Owin;

    public class QueryStringBearerAuthorizeAttribute : AuthorizeAttribute
    {
        public override bool AuthorizeHubConnection(HubDescriptor hubDescriptor, IRequest request)
        {
            var token = request.QueryString.Get("Bearer");
            var authenticationTicket = Startup.AuthServerOptions.AccessTokenFormat.Unprotect(token);

            if (authenticationTicket == null || authenticationTicket.Identity == null || !authenticationTicket.Identity.IsAuthenticated)
            {
                return false;
            }

            request.Environment["server.User"] = new …
Run Code Online (Sandbox Code Playgroud)

c# authentication token asp.net-web-api signalr.client

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