Vue Core 8

namespace WebApplication2
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);
            builder.Services.AddSpaStaticFiles(configuration: options => { options.RootPath = "wwwroot"; });
            builder.Services.AddControllers();
            builder.Services.AddCors(options =>
            {
                options.AddPolicy("VueCorsPolicy", cfg =>
                {
                    cfg
                        .AllowAnyHeader()
                        .AllowAnyMethod()
                        .AllowAnyOrigin();
                });
            });
            var app = builder.Build();
            if (!app.Environment.IsDevelopment())
            {
                app.UseHsts();
            }
            app.UseStaticFiles();
            app.UseSpaStaticFiles();
            app.UseRouting();
            app.UseEndpoints(endpoints => endpoints.MapControllers());
            app.UseCors("VueCorsPolicy");
            app.UseSpa(spa =>
            {
                if (app.Environment.IsDevelopment())
                {
                    spa.UseProxyToSpaDevelopmentServer("http://localhost:5173");
                }
            });
            app.Run();
        }
    }
}
  • 必须使用app.UseRouting();app.UseEndpoints(endpoints => endpoints.MapControllers());
  • app.MapControllers()这里无效
Install-package Microsoft.EntityFrameworkCore.Tools
Install-package Microsoft.EntityFrameworkCore.Sqlite
PM> Scaffold-DbContext "Data Source=.\database.db" Microsoft.EntityFrameworkCore.Sqlite -OutputDir Models
posted @ 2024-03-07 20:49  月渊  阅读(10)  评论(0编辑  收藏  举报