如何讲HangFile改成中文
第一步,你要了解中间件
添加:
app.UseMiddleware<zhognjianjian>();
app.UseStaticFiles();
这个顺序是你在断点调试的时候可以看到你中间件的数据
第二部:添加zhognjianjian类
public class zhognjianjian
{
private IHostEnvironment _webHostEnvironment;
private RequestDelegate _next;
public zhognjianjian(IHostEnvironment webHostEnvironment, RequestDelegate next)
{
this._webHostEnvironment = webHostEnvironment;
this._next = next;
}
public async Task InvokeAsync(HttpContext context)
{
var path = context.Request.Path.Value;
if (path.IndexOf("/js/site.js") > 0 && path != string.Empty)
{
//if (path.IndexOf("/js/site.js") >= 0 )
//{
var body = context.Response.Body;
using (var newbody = new MemoryStream())
{
context.Response.Body = newbody;
await _next(context);
context.Response.Body = body;
newbody.Seek(0, SeekOrigin.Begin);
var newContext = new StreamReader(newbody).ReadToEnd();
newContext += asdf();
await context.Response.WriteAsync(newContext);
}
}
else
{
await _next(context);
}
}
private string asdf()
{
var path = Path.Combine(_webHostEnvironment.ContentRootPath, "wwwroot", "js", "MyHeaderFire.js");
return File.ReadAllText(path);
}
}
当发现/js/site.js这个js路径的时候,将MyHeaderFire.js这个添加到管道中,
这个js文件的内容就是你修改hangFile的js内容
(function () {
//$(".navbar-brand").html("111")
document.getElementsByClassName("navbar-brand")[0].innerHTML = "11111"
})();
这样就可以实现修改中文了,这个是可以直接拿来用的
问题,这种可能会产生乱码需要添加gb2312
return File.ReadAllText(path, Encoding.GetEncoding("gb2312"));