[已解决].Net Core 3.0以上修改视图后刷新浏览器问题解决方案

KnifeZ 8/7/2020, 10:54:13 AM 66

在使用WTM框架时发现修改razor页面时,无论怎么刷新页面都不会变,除非重新生成,后来查阅文档发现需要启用运行时编译

官方文档: https://docs.microsoft.com/zh-cn/aspnet/core/mvc/views/view-compilation?view=aspnetcore-3.0

# 解决方法

1、 安装 Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation;

2、 在Program.cs中ConfigureServices修改如下


webBuilder.ConfigureServices(x =
{
    x.AddSignalR();
    x.AddFrameworkService();
    x.AddLayui();
    x.AddSwaggerGen(c =
    {
        c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
        var bearer = new OpenApiSecurityScheme()
        {
            Description = "JWT Bearer",
            Name = "Authorization",
            In = ParameterLocation.Header,
            Type = SecuritySchemeType.ApiKey

        };
        c.AddSecurityDefinition("Bearer", bearer);
        var sr = new OpenApiSecurityRequirement();
        sr.Add(new OpenApiSecurityScheme
        {
            Reference = new OpenApiReference
            {
                Type = ReferenceType.SecurityScheme,
                Id = "Bearer"
            }
        }, new string[] { });
        c.AddSecurityRequirement(sr);
    });
    //自动刷新前端页面 --添加该段代码即可
    //需引用  Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
    x.AddRazorPages().AddRazorRuntimeCompilation();
});
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

#Tags

WTMBug记录