创建用自定义令牌交换 .Net Auth Cookie 的 Owin Auth 提供程序

2023-12-24

我正在尝试在 2 个 .Net 应用程序之间创建类似 SSO 的解决方案 .Net 应用程序 1 有一个自定义令牌生成器和端点来验证返回用户信息的令牌。

.Net 应用程序 2 使用 Owin 进行保护,是一个典型的独立应用程序,用户可以使用密码和用户名直接登录。

我创建了(基于对编码博客的热情 https://coding.abel.nu/2014/06/writing-an-owin-authentication-middleware/ and Github https://github.com/AndersAbel/DummyOwinAuth) 一个自定义 Owin 提供程序,该提供程序将在授权标头中查找令牌,或者从链接中查找令牌作为查询参数,用户单击 .Net 应用程序 1 中的链接并将查询字符串中的令牌发送到 .Net 应用程序 2就像 GET 一样(我知道这不安全,我们最终将使用 OpenID 来实现它的价值,我们只需要它来进行演示)。我能够获取令牌对其进行验证并创建身份并进行身份验证,但我无法让提供程序创建 .Net Auth Cookie,以便对后续请求进行身份验证并且不会给出 401 错误。

处理程序文件:

using Microsoft.Owin.Infrastructure;
using Microsoft.Owin.Logging;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Infrastructure;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;

namespace SomeOAuth
{
// Created by the factory in the someAuthenticationMiddleware class.
class SomeAuthenticationHandler : AuthenticationHandler<SomeAuthenticationOptions>
{
    private const string HandledResponse = "HandledResponse";

    private readonly ILogger _logger;
    private readonly string _challenge;

    /// <summary>
    /// Creates a new OpenIdConnectAuthenticationHandler
    /// </summary>
    /// <param name="logger"></param>
    public SomeAuthenticationHandler(ILogger logger, string challenge)
    {
        _logger = logger;
        _challenge = challenge;
    }


    protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
    {
        // ASP.Net Identity requires the NameIdentitifer field to be set or it won't  
        // accept the external login (AuthenticationManagerExtensions.GetExternalLoginInfo)
        string requestToken = null;
        string authorization = Request.Headers.Get("Authorization");

        if (!string.IsNullOrEmpty(authorization))
        {
            if (authorization.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
            {
                requestToken = authorization.Substring("Bearer ".Length).Trim();
            }
        }

        if (string.IsNullOrEmpty(requestToken))
        {
            string accessTokenParam = Request.Query.Get("access_token");
            if (!string.IsNullOrEmpty(accessTokenParam))
            {
                requestToken = accessTokenParam;
            }
        }

        if (!string.IsNullOrEmpty(requestToken))
        {
            using (var client = new HttpClient())
            {
                try
                {
                    var request = new HttpRequestMessage(HttpMethod.Post, "https://testserver/API/Auth/Authenticate");
                    var s = new StringContent("{\"oauthtoken\":\"" + requestToken + "\"}", Encoding.UTF8, "application/json");
                    // var ts = s.ToString();
                    request.Content = new StringContent("{\"oauthtoken\":\"" + requestToken + "\"}", Encoding.UTF8, "application/json");

                    System.Diagnostics.Debug.WriteLine("Request:");
                    System.Diagnostics.Debug.WriteLine(request.ToString());
                    if (request.Content != null)
                    {
                        System.Diagnostics.Debug.WriteLine(await request.Content.ReadAsStringAsync());
                    }
                    System.Diagnostics.Debug.WriteLine("");

                    var response = await client.SendAsync(request);
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        return null;
                    }

                    var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
                    var userId = payload.Value<string>("username");

                    //need to get the useid of the user as well as the name and role

                    var identity = new ClaimsIdentity("Some");
                    identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "fakeuser", null, "Some"));
                    /*
                    identity.AddClaim(new Claim(ClaimTypes.GivenName, user.FirstName + " " + user.LastName));
                    identity.AddClaim(new Claim(ClaimTypes.Email, user.ContactInfo.Email));
                    identity.AddClaim(new Claim(ClaimTypes.Sid, user.Guid.ToString()));
                    */
                    identity.AddClaim(new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "Some"));
                    AuthenticationProperties properties = CreateProperties("fakeusername", "");
                    var ticket = new AuthenticationTicket(identity, new AuthenticationProperties());
                    return ticket;
                }
                catch (Exception e)
                {
                    Console.WriteLine("asdf e = " + e.Message);
                }
                return null;
            }
        }
        else
        {
            return null;
        }
    }

    /// <summary>
    /// Handles SignIn
    /// </summary>
    /// <returns></returns>
    protected override Task ApplyResponseChallengeAsync()
    {

        if (Response.StatusCode == 401)
        {
            AuthenticationResponseChallenge challenge = Helper.LookupChallenge(Options.AuthenticationType, Options.AuthenticationMode);
            if (challenge == null)
            {
                return null;
            }
        }

        return Task.FromResult<object>(null);
    }




    public override Task<bool> InvokeAsync()
    {
        return InvokeReplyPathAsync();
    }

    private async Task<bool> InvokeReplyPathAsync()
    {
        AuthenticationTicket ticket = await AuthenticateAsync();

        if (ticket != null)
        {
            string value;
            if (ticket.Properties.Dictionary.TryGetValue(HandledResponse, out value) && value == "true")
            {
                return true;
            }
            if (ticket.Identity != null)
            {
                Request.Context.Authentication.SignIn(ticket.Properties, ticket.Identity);
            }
            // Redirect back to the original secured resource, if any.
            if (!string.IsNullOrWhiteSpace(ticket.Properties.RedirectUri))
            {
                Response.Redirect(ticket.Properties.RedirectUri);
                return true;
            }
        }

        return false;
    }

    private static AuthenticationTicket GetHandledResponseTicket()
    {
        return new AuthenticationTicket(null, new AuthenticationProperties(new Dictionary<string, string>() { { HandledResponse, "true" } }));
    }

    public AuthenticationProperties CreateProperties(string userName, string Roles)
    {
        IDictionary<string, string> data = new Dictionary<string, string>
    {
        { "userName", userName },
        {"roles",Roles}
    };
        return new AuthenticationProperties(data);
    }

  }
}

中间件文件:

using Microsoft.Owin;
using Microsoft.Owin.Security.Infrastructure;
using Owin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.DataProtection;
using Microsoft.Owin.Security.DataHandler;
using Microsoft.Owin.Logging;

namespace SomeOAuth
{
    // One instance is created when the application starts.
    public class SomeeAuthenticationMiddleware : AuthenticationMiddleware<SomeAuthenticationOptions>
    {
        private readonly ILogger _logger;
        private readonly string _challenge = "Bearer";

        public SomeAuthenticationMiddleware(OwinMiddleware next, IAppBuilder app, SomeAuthenticationOptions options)
            : base(next, options)
        {

            _logger = app.CreateLogger<SomeAuthenticationMiddleware>();


        }

        // Called for each request, to create a handler for each request.
        protected override AuthenticationHandler<SomeAuthenticationOptions> CreateHandler()
        {
            return new SomeAuthenticationHandler(_logger, _challenge);
        }
    }
}

选项文件:

using Microsoft.Owin;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.OAuth;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SomeOAuth
{
    public class SomeAuthenticationOptions : AuthenticationOptions
    {
        public SomeAuthenticationOptions(string userName, string userId)
            : base(OAuthDefaults.AuthenticationType)
        {
            UserName = userName;
            UserId = userId;
        }

        public string Challenge { get; set; }

        public string UserName { get; set; }

        public string UserId { get; set; }

    }
}

扩展文件:

using Microsoft.Owin.Extensions;
using Owin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SomeOAuth
{

    public static class SomeAuthenticationExtensions
    {
        public static IAppBuilder UseSomeeAuthentication(this IAppBuilder app, SomeAuthenticationOptions options)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }

            app.Use(typeof(SomeAuthenticationMiddleware), app, options);
            app.UseStageMarker(PipelineStage.Authenticate);

            return app;
        }
    }
}

启动文件

using System;
using CoreLX.Palms.VS.Web.Services;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Owin.Security.Providers.OpenID;
using Microsoft.Owin.Security.OAuth;
using Owin;
using SomeOAuth;
using CoreLX.Palms.LS.Web.Common.Models.User;

namespace CoreLX.Palms.VS.Web
{
    public partial class Startup
    {

        public void ConfigureAuth(IAppBuilder app)
        {

            app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
        app.CreatePerOwinContext<ApplicationSignInManager>    (ApplicationSignInManager.Create);

            //app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions
            //{
            //    AccessTokenProvider = new SomeTokenProvider(),
            //    Provider = new SomeOAuthBearerAuthenticationProvider("access_token")
            //});

            app.UseSomeAuthentication(new SomeAuthenticationOptions("testuser", "9"));

            // Use a cookie to temp store information about a user     logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(
                new CookieAuthenticationOptions
                {
                    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                    LoginPath = new PathString("/Account/Login"),
                    ExpireTimeSpan = new TimeSpan(0, 3, 0, 0),
                    Provider = new CookieAuthenticationProvider
                    {
                        OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)),
                        OnApplyRedirect = ctx =>
                                {
                                // don't redirect to login page for webapi/ajax requests
                                // http://brockallen.com/2013/10/27/using-cookie-authentication-middleware-with-web-api-and-401-response-codes/
                                if (!IsWebApiRequest(ctx.Request))
                                {
                                    ctx.Response.Redirect(ctx.RedirectUri);
                                }
                            }
                    }
                });



            app.UseOpenIDAuthentication("http://me.yahoo.com/", "Yahoo");



        }


        private static bool IsWebApiRequest(IOwinRequest request)
        {
            // hack for check if it's webapi requesr
            if (request.Path.StartsWithSegments(new PathString("/api")))
            {
            return true;
            }

            // checks if it's ajax request
            IReadableStringCollection query = request.Query;
            if ((query != null) && (query["X-Requested-With"] == "XMLHttpRequest"))
            {
                return true;
            }
            IHeaderDictionary headers = request.Headers;
            return ((headers != null) && (headers["X-Requested-With"] ==     "XMLHttpRequest"));
    }
    }
}

我还尝试仅使用自定义提供程序来提供标准

OAuthBearerAuthenticationProvider

这是我尝试过的插件/提供程序的代码,只要没有 401 错误,我就没有偏好:

Provider

using Microsoft.Owin.Security.OAuth;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SomeOAuth
{
    public class SomeOAuthBearerAuthenticationProvider : IOAuthBearerAuthenticationProvider
    {
        readonly string _parameterName;
        public SomeOAuthBearerAuthenticationProvider(string parameterName)
        {
            _parameterName = parameterName;
        }
        public Task ApplyChallenge(OAuthChallengeContext context)
        {
            return Task.FromResult<object>(null);
        }

        public Task RequestToken(OAuthRequestTokenContext context)
        {
            string token = context.Token;
            if(string.IsNullOrEmpty(token) &&     !string.IsNullOrEmpty(_parameterName))
            {
                token = context.Request.Query.Get(_parameterName);
            }

            if (!string.IsNullOrEmpty(token))
            {
                context.Token = token;
            }

            return Task.FromResult<object>(null);
        }

        public Task ValidateIdentity(OAuthValidateIdentityContext context)
        {
            context.Validated();
            return Task.FromResult<object>(null);
        }
    }
}

和 AccessTokenProvider

using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Infrastructure;
using Newtonsoft.Json.Linq;
using System;
//using Newtonsoft.Json.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;


namespace SomeOAuth
{
    public sealed class SomeTokenProvider : AuthenticationTokenProvider
    {
        public override async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            using (var client = new HttpClient())
            {
                try
                {
                    var request = new HttpRequestMessage(HttpMethod.Post, "https://someserver/API/Auth/Authenticate");
                    var s = new StringContent("{\"oauthtoken\":\"" + context.Token + "\"}", Encoding.UTF8, "application/json");
                    // var ts = s.ToString();
                    request.Content = new StringContent("{\"oauthtoken\":\"" + context.Token + "\"}", Encoding.UTF8, "application/json");

                    System.Diagnostics.Debug.WriteLine("Request:");
                    System.Diagnostics.Debug.WriteLine(request.ToString());
                    if (request.Content != null)
                    {
                        System.Diagnostics.Debug.WriteLine(await request.Content.ReadAsStringAsync());
                    }
                    System.Diagnostics.Debug.WriteLine("");

                    var response = await client.SendAsync(request);
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        return;
                    }

                    var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
                    var userId = payload.Value<string>("username");

                    //need to get the useid of the user as well as the name and role

                    var identity = new ClaimsIdentity("Some");
                    identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "someuser", null, "Some"));
                /*
                    identity.AddClaim(new Claim(ClaimTypes.GivenName, user.FirstName + " " + user.LastName));
                    identity.AddClaim(new Claim(ClaimTypes.Email, user.ContactInfo.Email));
                    identity.AddClaim(new Claim(ClaimTypes.Sid, user.Guid.ToString()));
                    */
                    identity.AddClaim(new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "Some"));
                    context.SetTicket(new AuthenticationTicket(identity, new AuthenticationProperties()));
                }
                catch (Exception e)
                {
                    Console.WriteLine("asdf e = " + e.Message);
                }
            }
        }
    }
}

您以错误的顺序注册中间件。 owin 中间件模型通过 auth 中间件放置指令来工作(AuthenticationResponseGrant) 在owin字典中,然后返回到之前的中间件。如果之前的中间件是外部 cookie 中间件,它将发出一个 cookie。有更详细的内容我的博文 https://coding.abel.nu/2014/06/understanding-the-owin-external-authentication-pipeline/。所以交换这两行:

// Use a cookie to temp store information about a user logging in with a third party login provider 
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

app.UseSomeAuthentication(new SomeAuthenticationOptions("testuser", "9"));

还有另一个问题。这AuthenticationType身份的身份必须与 cookie 中间件的身份匹配。这UseExternalSignInCookie方法内部调用app.SetDefaultSignInAsAuthenticationType所以当你创建新的ClaimsIdentity你不应该使用Some作为身份验证类型,而是传达以下结果app.GetDefaultSignInAsAuthenticationType()通过SignInAsAuthenticationType在选项类上。致电给app.GetDefaultSignInAsAuthenticationType()通常在中间件构造函数中完成。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

创建用自定义令牌交换 .Net Auth Cookie 的 Owin Auth 提供程序 的相关文章

  • 复制目录内容

    我想将目录 tmp1 的内容复制到另一个目录 tmp2 tmp1 可能包含文件和其他目录 我想使用C C 复制tmp1的内容 包括模式 如果 tmp1 包含目录树 我想递归复制它们 最简单的解决方案是什么 我找到了一个解决方案来打开目录并读
  • 使用 Newtonsoft 和 C# 反序列化嵌套 JSON

    我正在尝试解析来自 Rest API 的 Json 响应 我可以获得很好的响应并创建了一些类模型 我正在使用 Newtonsoft 的 Json Net 我的响应中不断收到空值 并且不确定我的模型设置是否正确或缺少某些内容 例如 我想要获取
  • 如何创建包含 IPv4 地址的文本框? [复制]

    这个问题在这里已经有答案了 如何制作一个这样的文本框 我想所有的用户都见过这个并且知道它的功能 您可以使用带有 Mask 的 MaskedTestBox000 000 000 000 欲了解更多信息 请参阅文档 http msdn micr
  • 为什么 Google 测试会出现段错误?

    我是 Google Test 的新手 正在尝试提供的示例 我的问题是 当我引入失败并设置GTEST BREAK ON FAILURE 1 或使用命令行选项 GTest 将出现段错误 我正在考虑这个例子 https code google c
  • 在 iFrame 内维护会话状态

    不确定我是否疯了 但我在 iFrame 内的会话状态遇到问题 它是一个域在另一个域中的简单设置 我不需要跨域共享任何内容 我想做的就是将一个网站嵌入到另一个网站中 并且我希望该嵌入网站能够使用 cookie 会话状态登录 编辑 更新 等 为
  • 在 C 中初始化变量

    我知道有时如果你不初始化int 如果打印整数 您将得到一个随机数 但将所有内容初始化为零似乎有点愚蠢 我问这个问题是因为我正在评论我的 C 项目 而且我对缩进非常直接 并且它可以完全编译 90 90 谢谢 Stackoverflow 但我想
  • DbContext 和 ObjectContext 有什么区别

    From MSDN 表示工作单元和存储库模式的组合 使您能够查询数据库并将更改分组在一起 然后将这些更改作为一个单元写回存储 DbContext在概念上类似于ObjectContext 我虽然DbContext只处理与数据库的连接以及针对数
  • 如何在 32 位或 64 位配置中以编程方式运行任何 CPU .NET 可执行文件?

    我有一个可在 32 位和 64 位处理器上运行的 C 应用程序 我试图枚举给定系统上所有进程的模块 当尝试从 64 位应用程序枚举 32 位进程模块时 这会出现问题 Windows 或 NET 禁止它 我认为如果我可以从应用程序内部重新启动
  • 如何在 Xaml 文本中添加电子邮件链接?

    我在 Windows Phone 8 应用程序中有一些大文本 我希望其中有电子邮件链接 例如 mailto 功能 这是代码的一部分
  • 使用自定义堆的类似 malloc 的函数

    如果我希望使用自定义预分配堆构造类似 malloc 的功能 那么 C 中最好的方法是什么 我的具体问题是 我有一个可映射 类似内存 的设备 已将其放入我的地址空间中 但我需要获得一种更灵活的方式来使用该内存来存储将随着时间的推移分配和释放的
  • 使用

    因此 我决定开始使用 C 进行编程 我所做的一件事就是创建一个 pausec exe pause exe 克隆 它有效 但是当像这样调用它时 lt nul pausec 它崩溃了 据我所知 我得到的错误是这样的 未处理的异常 System
  • C#:帮助理解 UML 类图中的 <>

    我目前正在做一个项目 我们必须从 UML 图编写代码 我了解 UML 类图的剖析 但我无法理解什么 lt
  • 如何禁用 fread() 中的缓冲?

    我正在使用 fread 和 fwrite 读取和写入套接字 我相信这些函数用于缓冲输入和输出 有什么方法可以在仍然使用这些功能的同时禁用缓冲吗 Edit 我正在构建一个远程桌面应用程序 远程客户端似乎 落后于服务器 我不知道可能是什么原因
  • “接口”类似于 boost::bind 的语义

    我希望能够将 Java 的接口语义与 C 结合起来 起初 我用过boost signal为给定事件回调显式注册的成员函数 这非常有效 但后来我发现一些函数回调池是相关的 因此将它们抽象出来并立即注册所有实例的相关回调是有意义的 但我了解到的
  • 动态添加 ASP.Net 控件

    我有一个存储过程 它根据数据库中存储的记录数返回多行 现在我想有一种方法来创建 div 带有包含该行值的控件的标记 如果从数据库返回 10 行 则 10 div 必须创建标签 我有下面的代码来从数据库中获取结果 但我不知道如何从这里继续 S
  • 如何在非控制台应用程序中查看 cout 输出?

    输出到调试窗口似乎相当繁琐 我在哪里可以找到cout如果我正在编写非控制台信息 则输出 Like double i a b cout lt lt b lt lt endl I want to check out whether b is z
  • 使用 %d 打印 unsigned long long

    为什么我打印以下内容时得到 1 unsigned long long int largestIntegerInC 18446744073709551615LL printf largestIntegerInC d n largestInte
  • 方法优化 - C#

    我开发了一种方法 允许我通过参数传入表 字符串 列数组 字符串 和值数组 对象 然后使用这些参数创建参数化查询 虽然它工作得很好 但代码的长度以及多个 for 循环散发出一种代码味道 特别是我觉得我用来在列和值之间插入逗号的方法可以用不同的
  • 无法接收 UDP Windows RT

    我正在为 Windows 8 RT 编写一个 Windows Store Metro Modern RT 应用程序 需要在端口 49030 上接收 UDP 数据包 但我似乎无法接收任何数据包 我已按照使用教程进行操作DatagramSock
  • 从列表中选择项目以求和

    我有一个包含数值的项目列表 我需要使用这些项目求和 我需要你的帮助来构建这样的算法 下面是一个用 C 编写的示例 描述了我的问题 int sum 21 List

随机推荐

  • 如果我使用 HTML5 文档类型,为什么不能将 div 设为 100% 高度?如何获得 100% 高度

    我正在努力为一个非常简单的画廊 Web 应用程序排序布局 但是当我使用 HTML5 文档类型声明时 我的一些 div 的高度 100 会立即缩小 而且我似乎无法丰满他们使用 CSS 进行备份 我的 HTML 位于https dl dropb
  • 使用Python进行Windows进程管理

    我需要一个脚本来检查特定进程是否正在运行 如果找不到则返回一些内容 我知道这可以使用子进程来完成 但是有没有更简单的方法来做到这一点 在 Windows 上 您可以使用 WMI import win32com client def find
  • 如何在 C# 异常中获取错误号而不是错误消息? [复制]

    这个问题在这里已经有答案了 有没有一种方法可以获取相应的错误代码Exceptions 我需要抛出的异常错误代码而不是其消息 以便我根据错误代码向用户显示正确的消息 如果您正在寻找 win32 错误代码 可以在Win32Exception h
  • 浮动嵌套div的填充高度

    我正在制作一个基本的评论系统 当评论很短时它是完美的 但是当用户写很多时 评论并不像应有的那么花哨 我尝试用高度 100 但它并没有像我预期的那样工作 我希望作者信息填写评论的高度 到目前为止我尝试过的 http jsfiddle net
  • 从新的 youtu.be 网址获取视频 ID

    我有以下代码 可以从旧的共享网址中获取 youtube 的视频 id youtube com watch v adasdalkjsd url GET url parse str parse url url PHP URL QUERY que
  • Glassfish 线程池、接受器线程、HTTP 最大连接数

    请参阅附图 请帮助我理解线程池 最大和最小线程池大小 接受器线程及其最大连接数和 HTTP 最大连接数之间的关系 线程池 HTTP 传输TCP 首先我给你一些官方文档 线程池 线程池是服务器可以处理的并发请求的最大数量 服务器有一个连接队列
  • 使用 EF 和 WebApi 序列化父/子对象

    我在实体框架内有以下模型 public class Customer XmlIgnore public virtual ICollection
  • 刷新/重新启动 PowerShell 会话而不退出

    我一直在调整我的 PowerShell 配置文件中的一些脚本 退出 powershell 然后重新启动它很烦人 这样它就会加载我对我的配置文件中的脚本所做的任何更改 是否可以在不退出的情况下重新启动 powershell 会话 你可以这样做
  • Rails 4 参数数量错误(2 为 1)。可能是 Strong_params 问题

    我将 Rails 4 与 Devise Cancan 和 Rollify 一起使用 我有一个用户索引 其中包含更改角色的模式 但是 当我尝试更新角色时 出现以下错误 参数数量错误 2 为 1 错误发生在我的用户控制器代码的第 16 行 13
  • Oracle 11g 通过正则表达式获取所有匹配的出现

    我正在使用 Oracle 11g 我想使用 REGEXP SUBSTR 来匹配给定模式的所有出现情况 例如 SELECT REGEXP SUBSTR Txa233141b Ta233141 Ta233142 Ta233147 Ta23314
  • Animate.css动画完成后动画消失

    我正在尝试构建一个菜单 每个列表项都有一系列动画 它有效 但动画结束后该项目再次消失 看起来 animated 的可见属性没有被使用 您可以给我任何指示来解决这个问题吗 ul class menu ani item li class ani
  • E:存储库“http://archive.ubuntu.com/ubuntu precision Release”未签名

    我正在尝试通过运行此命令在本地设置 Scrapy docker env docker build t scrapy 我遇到以下错误 Get 20 http archive ubuntu com ubuntu http archive ubu
  • Chrome CustomTabs CustomTabsCallback onPostMessage 未调用

    我正在尝试在 Android 上使用 Chrome CustomTabs 但在使用 CustomTabsCallback 时遇到问题 因此 我在网上搜索了一些在我的代码中实现的示例或文档 但不幸的是我没有找到任何东西 我需要接收托管网页发送
  • Java 中的事件监听器和处理程序有什么区别?

    一般来说 java 中有事件的侦听器和处理程序 我的意思是我在不知不觉中使用它们 只是 API 中可用的 我的问题是 在什么情况下我们使用侦听器以及在什么情况下使用事件处理程序 他们之间有什么区别 特征 我搜索了原因 但找不到 Java 的
  • ConEmu 与 Git Bash - 在选项卡栏中显示文件夹

    我通常在 ConEmu 选项卡中运行 Git Bash 在每个 Git Bash 实例的选项卡栏中显示当前目录的名称确实很方便 但如果我将选项卡模板设置为 d or f 无论我在哪里 我总是可以获得我的 Windows 主目录cd到 Git
  • Apple OS X Server(Xcode CI 服务)找不到配置文件

    我配置了带有 OS X Server 的专用 Mac mini 以便与 XCode5 持续集成 添加了 git 存储库并创建了机器人 我正在尝试集成机器人并收到错误 Specified PROVISIONING PROFILE 29DAD4
  • 如何禁用 Hadoop Kerberos

    我使用内部脚本来设置 Hadoop 集群 默认情况下 它使用 Kerberos 配置 Hadoop 安全性 这对于开发环境来说是非常不方便的 我用谷歌搜索了很多 但结果都是关于 如何启用 请帮忙给一些参考或者建议 更改以下值 core si
  • 将供应商 Android 更改集成到 aosp 中

    我正在尝试将 AOSP 设备更改集成到标准 AOSP 本地镜像中 这有点令人困惑 但我会尽力尽可能清楚 我在服务器 不同的本地计算机 上创建了 AOSP 存储库的本地镜像 供应商补丁基于标签 android 4 3 r2 1 所以我初始化了
  • 如何在 DataFrame 中跨组使用 QuantileDiscretizer?

    我有一个包含以下列的数据框 scala gt show times printSchema root account string nullable true channel string nullable true show name s
  • 创建用自定义令牌交换 .Net Auth Cookie 的 Owin Auth 提供程序

    我正在尝试在 2 个 Net 应用程序之间创建类似 SSO 的解决方案 Net 应用程序 1 有一个自定义令牌生成器和端点来验证返回用户信息的令牌 Net 应用程序 2 使用 Owin 进行保护 是一个典型的独立应用程序 用户可以使用密码和