Visual studio 如何在带有ntlm的VS项目中使用浏览器同步

Visual studio 如何在带有ntlm的VS项目中使用浏览器同步,visual-studio,authentication,browser-sync,Visual Studio,Authentication,Browser Sync,我有一个asp.NETMVC项目,在这个项目中,我想在我的gulp文件中使用浏览器同步来自动插入css更改,并在我对站点进行更改时重新加载页面。我以前在proxy模式下做过这件事,但是这个站点使用的是windows身份验证(NTLM),不能按原样进行代理。是否有办法使浏览器同步工作?是的,浏览器同步适用于代理无法工作的情况。一般情况下,只需将一个代码片段剪切并粘贴到页面主体中,就可以获得注入/重新加载支持。然而,这是一项长期的体力劳动 我想出了一个消除手工劳动的惯例 首先添加到您的Web.con

我有一个asp.NETMVC项目,在这个项目中,我想在我的gulp文件中使用浏览器同步来自动插入css更改,并在我对站点进行更改时重新加载页面。我以前在
proxy
模式下做过这件事,但是这个站点使用的是windows身份验证(NTLM),不能按原样进行代理。是否有办法使浏览器同步工作?

是的,浏览器同步适用于代理无法工作的情况。一般情况下,只需将一个代码片段剪切并粘贴到页面主体中,就可以获得注入/重新加载支持。然而,这是一项长期的体力劳动

我想出了一个消除手工劳动的惯例

首先添加到您的
Web.config

  <configuration>
      <appSettings>
          <add key="IncludeBrowserSync" value="true" />
          <!--...-->
      </appSettings>
      <!--...-->
  </configuration>
正如您在代码段中看到的,它将与browser sync告诉您剪切和粘贴的内容略有不同。主要区别在于,它不包括版本号(因此,
npm
可以在不破坏代码片段的情况下更新浏览器同步),并且它使用的端口号约定高于IISExpress提供的端口号


现在
上方添加
@Html.Partial(“BrowserSync”)
如果您使用gulp,可以尝试一下。如果使用gulp运行browsersync,它会自动注入browsersync代码段

var browserSync = require("browser-sync").create();

browserSync.use(require("bs-snippet-injector"), {
  // path to the file containing the closing </body> tag
  file: "wwwroot/index.html" 
});

gulp.task('watch', function() {
  // gupl.watch(...);
  browserSync.init(
    files: 'wwwroot/**'
  );
});
var browserSync=require(“浏览器同步”).create();
browserSync.use(需要(“bs代码段注入器”){
//包含结束标记的文件的路径
文件:“wwwroot/index.html”
});
吞咽任务('watch',function(){
//手表(…);
browserSync.init(
文件:“wwwroot/**”
);
});

使用aspnet 1.0更容易。您可以使用
标记,而不是使用webconfig
@using System.Configuration
@if (ConfigurationManager.AppSettings["IncludeBrowserSync"]?.ToLower().Contains("t") ?? false)
{
    <!-- BrowserSync:SNIPPET-->
    <script type='text/javascript' id="__bs_script__">
    //<![CDATA[
        document.write("<script async src='http://HOST:PORT/browser-sync/browser-sync-client.js'><\/script>".replace("HOST", location.hostname).replace("PORT", parseInt(location.port) + 1));
        //]]>
    </script>
    <!-- BS:BrowserSyncs:END-->
}
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
...
var dllName = "<YourProjectName>.dll";
var iisPort = <YourPortNumber>;

gulp.task('serve', ['default'], function () {

    browserSync.init({
        port: iisPort + 1;
    });

    gulp.watch("<your wildchar to find your editable css files>", ['compile-minimize-css']); 
    /*...*/
    gulp.watch("Views/**/*.cshtml").on('change', browserSync.reload);
    gulp.watch("bin/"+dllName).on('change', browserSync.reload);
});
var browserSync = require("browser-sync").create();

browserSync.use(require("bs-snippet-injector"), {
  // path to the file containing the closing </body> tag
  file: "wwwroot/index.html" 
});

gulp.task('watch', function() {
  // gupl.watch(...);
  browserSync.init(
    files: 'wwwroot/**'
  );
});