【问题标题】:webpack-dev-server hot reloading proxy IIS Express with Windows authentication (NTLM Authentication)webpack-dev-server 热重载代理 IIS Express 与 Windows 身份验证(NTLM 身份验证)
【发布时间】:2018-05-28 09:43:04
【问题描述】:

我创建了一个新的ASP.NET Web Application -> 带有 Windows 身份验证的 Web API 2 项目。这在 IIS Express 中运行良好,但为了让我的 React 前端热重新加载,我尝试使用 webpack-dev-server 并让它代理我的 IIS Express。我之前使用过 cookie 身份验证和令牌(承载)身份验证都没有问题,但使用 Windows 身份验证(NTLM 身份验证)它不起作用。

查看来自服务器的响应,我得到了预期的401 Unauthorized (401.2) 响应,标题为www-authenticate: Negotiate, NTLM,但我认为客户端不会使用Authorization: NTLM 重新发送请求。

我尝试过的浏览器(Chrome、Firefox 和 IE)也没有正常提示我输入正确的凭据。

https://blogs.msdn.microsoft.com/chiranth/2013/09/20/ntlm-want-to-know-how-it-works/

我在 webpack.config.js 中的设置如下所示:

var proxy = 'localhost:57263';

devServer: {
    proxy: {
        '*': {
            target: 'http://' + proxy,
            changeOrigin: true,
        },
        port: 8080,
        host: '0.0.0.0',
        hot: true,
    },
}

【问题讨论】:

    标签: c# asp.net reactjs iis webpack-dev-server


    【解决方案1】:

    查看webpack-dev-server Proxy 的文档后,我看到他们使用http-proxy-middleware

    https://webpack.github.io/docs/webpack-dev-server.html#proxy

    这让我找到了这个帖子并回答:

    https://github.com/chimurai/http-proxy-middleware/issues/39#issuecomment-330911943

    最终解决方案:

    运行:

    npm install agentkeepalive --save
    

    工作代码:

    var proxy = 'localhost:57263';
    
    devServer: {
        proxy: {
            '*': {
                target: 'http://' + proxy,
                changeOrigin: true,
                agent: new agent({
                    maxSockets: 100,
                    keepAlive: true,
                    maxFreeSockets: 10,
                    keepAliveMsecs: 100000,
                    timeout: 6000000,
                    keepAliveTimeout: 90000 // free socket keepalive for 90 seconds
                }),
                onProxyRes: (proxyRes) => {
                    var key = 'www-authenticate';
                    proxyRes.headers[key] = proxyRes.headers[key] && proxyRes.headers[key].split(',');
                },
            },
            port: 8080,
            host: '0.0.0.0',
            hot: true,
        },
    }
    

    【讨论】:

    • 嗨 Ogglas,我如何让 IISExpress 和 webpackdevserver 一起工作。这是我面临的问题stackoverflow.com/questions/54216912/… 非常感谢任何帮助
    • 谢谢,效果很好。但是对于带有 https 的目标,您需要使用 HttpsAgent: const agent = require('agentkeepalive').HttpsAgent;
    猜你喜欢
    • 1970-01-01
    • 2011-06-13
    • 1970-01-01
    • 1970-01-01
    • 2016-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多