小编Adr*_*ian的帖子

在Windows窗体中使用HttpClient类中的DelegatingHandler - 尚未设置内部处理程序

首先,我收到的错误消息如下: 尚未设置内部处理程序

我正在编写一个自定义消息处理程序来处理我的API的身份验证cookie超时.例如,如果我的代码库调用API然后接收401,那么它应该重试登录URL以获取更新的cookie.我打算按如下方式完成此任务:

public class CkApiMessageHandler : DelegatingHandler
{
    private readonly string _email;
    private readonly string _password;
    private const string _loginPath = "Account/Login";

    public CkApiMessageHandler(string email, string password)
    {
        _email = email;
        _password = password;

        //InnerHandler = new HttpControllerDispatcher(null);
    }

    protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {

        var response = await base.SendAsync(request, cancellationToken);

        if(response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
        {
            Logging.Logger.LogInformation("Authentication cookie timed out");
            var baseAddress = request.RequestUri.Host;
            var loginPath = baseAddress + _loginPath;

            var originalRequest = request;

            var loginRequest = …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-web-api

15
推荐指数
2
解决办法
7518
查看次数

在调试AzureFunction以及部署azure函数时缺少ProviderName

我有一个问题是DbContext从我的正确拉出我的连接字符串local.settings.json

语境:

  • 这是一个Azure功能项目
  • 主要问题代码是 System.Data.Entity.Internal.AppConfig
  • 虽然我有一个local.settings.json文件,但这不是dotnet核心.这是.net 4.6.1

错误信息:

'应用程序配置文件中的连接字符串'ShipBob_DevEntities'不包含必需的providerName属性."'

Json配置:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "AzureWebJobsDashboard": ""
},

"ConnectionStrings": {
"ShipBob_DevEntities": {
  "ConnectionString": "metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string='data source=***;initial catalog=***;persist security info=True;User Id=***;Password=***;;multipleactiveresultsets=True;application name=EntityFramework'",
  "providerName": "System.Data.EntityClient"
    }
  }
}  
Run Code Online (Sandbox Code Playgroud)

配置版本测试:

  • 将提供程序名称移动到实际的ConnectionString标记值:相同的错误ocurrs
  • provider属性内的ConnectionString属性设置为EntityClient:这没有做任何事情
  • 使ShipBob_DevEntities字符串值=为值ConnectionString:这会引发新的错误

    不支持关键字元数据

  • 我尝试使用ADO连接字符串,该字符串抛出code first异常,当您的连接字符串在database first方法中不正确时,似乎会发生异常.

我已经冒昧地EntityFramework.dll使用dotPeek进行反编译,并将问题追溯到System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig.在这个方法中,有一个调用LazyInternalConnection.FindConnectionInConfig吐出一个ConnectionStringSettings对象,该对象的ProviderName …

c# entity-framework azure azure-functions

12
推荐指数
2
解决办法
3798
查看次数

内存使用情况,CPU时间,数据输出和文件系统存储如何应用于我的网站?

原谅我的无知,但我有几个问题,我似乎无法通过搜索这里或谷歌得到答案.这些问题似乎完全是愚蠢的,但老实说我需要帮助.

在我的Azure网站门户网站上,我有一些我很好奇的东西.

CPU-Time如何应用于我的网站?我不知道我如何使用CPU,除非这适用于托管某种类型的应用程序?我使用此"站点"作为表单将数据提交到我的数据库.

"数据输出"究竟是什么意思?我每天允许165mb.

文件系统存储究竟是什么?这是我的Azure服务器上可用于存储我的项目以及我可能直接托管的任何其他内容的实际空间吗?

最后一个问题是,在这种情况下,内存使用情况如何?我被允许每小时1024mb.

我知道CPU-Time在桌面计算和内存使用方面是什么,但我不确定这如何适用于我的网站.如果我将超过任何这些限制以便我可以升级我的网站,我不知道我将如何投影.

azure azure-web-sites

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

多重性和EF 6的问题

这发生在没有地方.我之前从未遇到过这个问题.我刚刚在我的SQL Azure数据库中添加了一个表,该数据库将为注册我们的电子邮件列表的人保留电子邮件.没有关联到该表的关联,它只是单独的.我回到VS并从我的数据库更新我的模型,现在得到这些错误.

Error   1   Error 113: Multiplicity conflicts with the referential constraint in Role 'Category' in relationship 'FK_Items_3'. Because all of the properties in the Dependent Role are non-nullable, multiplicity of the Principal Role must be '1'.    C:\Users\chuyita\Documents\Visual Studio 2012\Projects\gcaMusicExchange\gcaMusicExchange\myConnection.edmx  1043    11  gcaMusicExchange
Run Code Online (Sandbox Code Playgroud)

Error   2   Error 113: Multiplicity conflicts with the referential constraint in Role 'Manufacturer' in relationship 'FK_Items_4'. Because all of the properties in the Dependent Role are non-nullable, multiplicity of the Principal Role must be '1'.    C:\Users\chuyita\Documents\Visual …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework

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

用于IONIC2应用程序和Identity Server4的OAuth流程

在过去的一天半里,我一直在研究oauth 2和IdentityServer4,可以说我认为在这种情况下使用的首选方法是hybrid flow.似乎在过去,这是implicit由于移动客户端无法保护secret.然后它似乎变成了authorization flow没有秘密...(不知道这将如何工作)

我对IONIC和其他跨平台框架的理解是它们通过将应用程序嵌入到a中来工作web view,因此这就是我的困惑所在.从技术上讲,混合流程建议用于native应用程序而IONIC不是允许您构建native应用程序的东西.

如果本机应用程序的推荐流程是混合的,但您使用的是IONIC,因此没有构建本机应用程序,那么混合流程是否仍适用?

同样,我的猜测确实如此,因为这将是一个在最终用户的机器上本地运行的应用程序,那么秘密在那里是不安全的.

这也让我更加困惑,因为还有其他流程,例如:credential based必须提供用户名和密码的流程.这让我感到困惑,因为这通常是用户希望用户在移动应用中进行身份验证的方式.混合流似乎是一个不需要用户名和密码的流程.

我来自MVC4 Owin背景.

我的基本架构计划是这样的

  • 验证服务器
  • API
  • IONIC app

oauth asp.net-web-api .net-core identityserver4

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

故障使用.net micro fw轮询超声波传感器的脉冲宽度

我正在关注使用Parallax Ping传感器连接C#和.net微框架的许多示例之一.

视差
http://learn.parallax.com/KickStart/28015

教程1
https://www.ghielectronics.com/community/codeshare/entry/123

教程2
http://forums.netduino.com/index.php?/topic/1721-parallax-ping-ultrasonic-sensor/

我的传感器正确连接到我的netduino加'5v输出,接地和gpio 0.(我尝试过不同的端口,但结果仍然相同.

我遇到的问题是我的程序检测到高脉冲但从未检测到脉冲的低电平.它会停留在每个教程中的第二个while(while)循环中.此外,我的视差LED似乎仍然存在,并且根据文档记录它应该在每次ping爆发时发出脉冲,而不是无限期地停留.我使用了MS.SPOT.CPU.GPIO0以及SecretLabs Pins.GPIOD0枚举.秘密实验室引脚产生一个闪烁的LED,从不退出第一个while(真)循环,而MS.SPOT端口产生一个永远不会退出第二个while(真)循环的LED灯.这是我在MF编程的第一天.任何人都可以帮我指出可能是什么问题吗?

布线

它的视频在行动https://dl.dropboxusercontent.com/u/62170850/20140606_153029.mp4

看起来我连接到引脚10和13,但我不是.这个角度有误导性.我实际上是插入Gnd和11

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
using Micro_Base_Lib;

namespace Parallax_Ping_Distance_Calculator
{
public class Program
{
    private static OutputPort onboardLed;
    private static InterruptPort onboardButton;
    public static void Main()
    {
        // write your code here
        //Cpu.GlitchFilterTime = new TimeSpan(0, 0, 0, 0, 5); //5 ms glitch filter

        onboardButton = new InterruptPort(Pins.ONBOARD_SW1, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLevelHigh);

        onboardButton.OnInterrupt += new …
Run Code Online (Sandbox Code Playgroud)

c# microcontroller .net-micro-framework netduino

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

OWIN/Identity 2.0 - 将pk从字符串更改为GUID

我试图从数据库nvarchar(128) - > uniqueidentifier和string - > Guid的代码中更改asp.net身份的pk系统.根据这篇文章基于将pk更改为int32我只有一个问题,我似乎无法解决.

在我的Startup.Auth.cs班上,我改变了以下内容

app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
            Provider = new CookieAuthenticationProvider
            {   //error on the line below
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser, Guid>(TimeSpan.FromMinutes(20), (manager, user) => user.GenerateUserIdentityAsync(manager), (identity) => Guid.Parse(identity.GetUserId()))
            }
        });  
Run Code Online (Sandbox Code Playgroud)

我得到两个我无法理解的错误.身份的结构使我与许多仿制药混淆了.我理解它说接收错误的参数类型,但我不知道如何解决这个问题.

错误

错误1"Microsoft.AspNet.Identity.Owin.SecurityStampValidator.OnValidateIdentity(System.TimeSpan,System.Func>,System.Func)"的最佳重载方法匹配具有一些无效参数

错误2参数2:无法从'lambda表达式'转换为'System.Func>'

任何人都可以提供一点见解吗?

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

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

ConfigurationManager.AppSettings 不适用于以编程方式创建的 App.config 文件

我遇到了一些有趣的事情。我正在尝试为我们的客户制作一个快速控制台应用程序,以便运行以更改他们某些程序上的一些连接字符串。这是客户的“快速应用程序”,我希望它是“白痴证明”。

该应用程序所做的主要事情之一是在找不到默认配置文件时重新创建它。

 if (!File.Exists("./App.config"))
        {
            Console.WriteLine("Config file is missing. Creating a new one now..");
            //file doesn't exist, let's create one.
            var doc = new XDocument(
                new XDeclaration("1.0", "UTF-16", null)
                ,new XElement("configuration"
                    , new XElement("startup"
                        , new XElement("supportedRuntime", new XAttribute("version", "v4.0")
                            , new XAttribute("sku", ".NETFramework,Version=v4.5")))
                , new XElement("appSettings"
                    , new XElement("add", new XAttribute("key", "targetDatabaseName"), new XAttribute("value", ""))
                    , new XElement("add", new XAttribute("key", "applicationServer"), new XAttribute("value", ""))
                    , new XElement("add", new XAttribute("key", "sqlServer"), new XAttribute("value", ""))
                    , new XElement("add", new XAttribute("key", "applicationServerPort"), …
Run Code Online (Sandbox Code Playgroud)

c# xml

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

从 catch 块中获取“未捕获(承诺中)错误”

我遇到了一个奇怪的错误,我已经为此苦苦挣扎了将近一天。看来我拒绝的承诺并没有被我的catch障碍所束缚。es6 async我对和有点陌生await;然而,它看起来与我在 C# 中习惯的非常相似。

Get: async function (request, cancelToken = null) {
console.info('Sending GET', request)
store.commit('global/setLoader', true)
let headers = getAuthTokenHeader()
try {
  var res = await Vue.axios({
    url: baseUrl + request.Url,
    params: request.Params,
    method: 'GET',
    headers
  }).catch(function (error) {
    console.error('Failed to GET: ' + error)
    if (typeof error.response !== 'undefined' && typeof error.response.data !== 'undefined' && error.response.data !== null) {
      throw new Error(error.response.data)
    } else {
      throw error
    }
  })
  console.info('Request received', res) …
Run Code Online (Sandbox Code Playgroud)

javascript async-await ecmascript-6

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

EF迁移:参数'frameworkName'不能为空字符串

我正在关注一些复数的教程,以了解如何使用.netcore设置我的第一个Web api。我在尝试运行首次迁移时遇到问题:

PM> Add-Migration InitialMigration Exception calling ".ctor" with "1" argument(s): "The parameter 'frameworkName' cannot be an empty string. Parameter name: frameworkName"

我理解这是在某个地方有一个构造函数,其中一个参数为空;但是,我不知道此“ frameworkName”参数在哪里。我假设这是一些内部EF机制。

该错误消息引用的是哪个类?

这是我简单的实体设置

public class ShackupContext : DbContext
{
    public DbSet<Post> Posts { get; set; }
    public ShackupContext(DbContextOptions<ShackupContext> options):base(options)
    {

    }
}  


    public class Post
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }
    [Required]
    [MaxLength(200)]
    public string Name { get; set; }
}  
Run Code Online (Sandbox Code Playgroud)

更新1 我已更新我的dbcontext,以按照@ViktorsTelle的建议调用基类构造函数。

我的项目的设置与我遵循的任何教程都不相同。主要区别是我的实体包含在自己的项目中,而不是api项目本身。
在此处输入图片说明
这使我相信,在Shackup.Data项目本身上运行Add-Migration并不需要我在api项目中注册dbcontext。无论如何,我都这样做是为了看看会发生什么:

 public void ConfigureServices(IServiceCollection services)
    {
        // Add framework …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework nuget entity-framework-core

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