.net 大摇大摆的用户界面-如何传递基于环境的URI?

.net 大摇大摆的用户界面-如何传递基于环境的URI?,.net,c#-4.0,asp.net-web-api2,swagger,swagger-ui,.net,C# 4.0,Asp.net Web Api2,Swagger,Swagger Ui,我已经在我的Web API项目中包含了用于Swagger UI的[dist]文件夹 但是当我去这个地方的时候 它不会自动指向 因此,当我直接访问此页面时,我会看到一个空文本框:---- 我希望文本框中填充 我希望这种情况根据环境动态发生。例如,如果我访问文本,则应自动填充文本 要回答您的第一个问题: 在index.html页面中,您可以拥有以下内容: <script type="text/javascript"> $(function() { window.swagg

我已经在我的Web API项目中包含了用于Swagger UI的[dist]文件夹

但是当我去这个地方的时候 它不会自动指向

因此,当我直接访问此页面时,我会看到一个空文本框:----

  • 我希望文本框中填充

  • 我希望这种情况根据环境动态发生。例如,如果我访问文本,则应自动填充文本


  • 要回答您的第一个问题:

    index.html
    页面中,您可以拥有以下内容:

    <script type="text/javascript">
    
      $(function() {
        window.swaggerUi = new SwaggerUi({
          url: "http://localhost:1234/swagger/docs/v1",
          ...
      });
    
    </script>
    
    <script type="text/javascript">
    
      // Initialize the url variable
      if (!window.location.origin) {
        window.location.origin = window.location.protocol + "//" +
          window.location.hostname + (window.location.port ? ':' +
            window.location.port : '');
      }
    
      $(function() {
        // Create the generated url
        var myUrl = window.location.origin + '/docs/v1';
    
        // Initialize the Swagger object
        window.swaggerUi = new SwaggerUi({
          url: myUrl,
          ...
        });
      });
    
    </script>
    
    
    $(函数(){
    window.swaggerUi=新的swaggerUi({
    url:“http://localhost:1234/swagger/docs/v1",
    ...
    });
    
    根据您访问的网站动态生成url,您可以执行以下操作:

    <script type="text/javascript">
    
      $(function() {
        window.swaggerUi = new SwaggerUi({
          url: "http://localhost:1234/swagger/docs/v1",
          ...
      });
    
    </script>
    
    <script type="text/javascript">
    
      // Initialize the url variable
      if (!window.location.origin) {
        window.location.origin = window.location.protocol + "//" +
          window.location.hostname + (window.location.port ? ':' +
            window.location.port : '');
      }
    
      $(function() {
        // Create the generated url
        var myUrl = window.location.origin + '/docs/v1';
    
        // Initialize the Swagger object
        window.swaggerUi = new SwaggerUi({
          url: myUrl,
          ...
        });
      });
    
    </script>
    
    
    //初始化url变量
    如果(!window.location.origin){
    window.location.origin=window.location.protocol+“/”+
    window.location.hostname+(window.location.port?):'+
    window.location.port:“”);
    }
    $(函数(){
    //创建生成的url
    var myUrl=window.location.origin+'/docs/v1';
    //初始化Swagger对象
    window.swaggerUi=新的swaggerUi({
    url:myUrl,
    ...
    });
    });