zoukankan      html  css  js  c++  java
  • .net core 在Startup.cs 的Configure方法中扩展 IApplicationBuilder

    using System;
    using System.Collections.Generic;
    using System.IO;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Http;
    using Microsoft.Extensions.Configuration;
    
    namespace Bayantu.Evos.WebApps.GJExhibition.Infrastructure.Extensions
    {
        public static class DomainConfigExtensions
        {
    
            public static IApplicationBuilder DomainConfigToJs(this IApplicationBuilder app, IConfiguration configuration)
            {
                string directoryPath = @"wwwroot//exhibition//static//js";          //设置文件路径
                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);                
                }
    
                // 文件路径
                var filePath = directoryPath + + @"//domain.js";if (File.Exists(filePath))
                {
                    ReadWriteContent(filePath, configuration);
                }
                else
                {
                    FileStream fs = new FileStream(filePath, FileMode.CreateNew);
                    fs.Close();
    
                    ReadWriteContent(filePath, configuration);                
                }
    
                Func<RequestDelegate, RequestDelegate> middleware = next =>
                {
                    return context =>
                    {
                        return next(context);
                    };
                };
    
                return app.Use(middleware);
            }
    
            private static void ReadWriteContent(string filePath, IConfiguration configuration) 
            {
                StreamWriter sw = new StreamWriter(filePath);
                JsContent(sw, configuration);
                sw.Flush();
                sw.Close();
            }
    
            public static void JsContent(StreamWriter sw, IConfiguration configuration) 
            {
                sw.WriteLine("window.domainConfig = {");
    
                sw.WriteLine($"'NewFileDomain': '{configuration["DomainConfig:NewFileDomain"]}',");
    
                sw.WriteLine("}");
            }
        }
    }
  • 相关阅读:
    How to change hostname on SLE
    How to install starDIct on suse OS?
    python logging usage
    How to reset password for unknow root
    How to use wget ?
    How to only capute sub-matched character by grep
    How to inspect who is caller of func and who is the class of instance
    How to use groovy script on jenkins
    Vim ide for shell development
    linux高性能服务器编程 (二) --IP协议详解
  • 原文地址:https://www.cnblogs.com/yxzs/p/12781274.html
Copyright © 2011-2022 走看看