标签:路径 wro contex ddl jscon mamicode iter pre window
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("}"); } } }
.net core 在Startup.cs 的Configure方法中扩展 IApplicationBuilder
标签:路径 wro contex ddl jscon mamicode iter pre window
原文地址:https://www.cnblogs.com/yxzs/p/12781274.html