惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
博客园_首页
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
小众软件
小众软件
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
罗磊的独立博客
V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell
IT之家
IT之家
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Recent Announcements
Recent Announcements
M
MIT News - Artificial intelligence
阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog

博客园 - woody.wu

开发我的第一个openclaw插件,接入本地查询客户信息的api接口。 在Ubuntu 24.04中安装openclaw全过程 配置qwen-code实现AI智能体编程,从此轻松让AI帮你写代码 使用spire.pdf绘制表格,当表格的内容超过一定长度会触发Index and length must refer to a location within the string AI写代码-window11安装claude code,以及在vs code中使用插件。 sqlserver 日志空间太满,导致磁盘空间不够的处理 在c#中利用MagickImage来实现图片的留白清除功能 利用扣子创建AI智能体大合集,智能体中包含有调用外部接口、意图识别、图片生成、大模型调用等 myql 8.0 安装随笔 SkiaSharp 在 Linux 上依赖一些系统级的库,需要确保这些库已经安装 2024 年年终总结 Quartz.NET学习笔记四->批量处理JOB 不同的JOB不同的时间执行不同的事情 真正实现可以编辑选择的下拉框--jquery 实现 jquery 实现图片轮换功能 - woody.wu - 博客园 在SQL Navigator 中做 oracle pl/sql SQL分析 [instant message]用asp.net+ jquery实现comet即时消息机制 ORACLE DBA学习笔记--使用LOGON TRIGGER限制用户登陆 ORACLE DBA学习笔记--管理归档日志文件 [简单分页]C#+JQUERY+ORACLE分页效果
.NET8作为VUE打包项目宿主部署的配置
woody.wu · 2025-02-27 · via 博客园 - woody.wu

using Microsoft.Extensions.FileProviders;
using System.Net;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorPages();

string IDentityIp = builder.Configuration["IDentity:IP"].ToString();
string IDentityPort = builder.Configuration["IDentity:Port"].ToString();
string IDentityAPIName = builder.Configuration["IDentity:APIName"].ToString();

string ServicePort = builder.Configuration["Service:Port"].ToString();
builder.WebHost.UseUrls("http://*:" + ServicePort + "");

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
}
app.UseStaticFiles();

app.UseRouting();

//自定义默认主页

DefaultFilesOptions defaultFilesOptions = new DefaultFilesOptions();
defaultFilesOptions.DefaultFileNames.Clear();
defaultFilesOptions.DefaultFileNames.Add("index.html");
app.UseDefaultFiles(defaultFilesOptions);
app.UseStaticFiles();

/* 兼容VUE宿主使用 可以防止出现404的错误 */
app.UseStaticFiles(new StaticFileOptions
{
    FileProvider = new PhysicalFileProvider(
               Path.Combine(Directory.GetCurrentDirectory(), "wwwroot")
           ),
    ServeUnknownFileTypes = true // 允许处理未知文件类型
});

// 如果非API请求,则重定向到Vue应用程序的入口文件
app.Run(async (context) =>
{
    context.Response.ContentType = "text/html";
    await context.Response.SendFileAsync(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "index.html"));
});
/* 兼容VUE宿主使用 可以防止出现404的错误 */

// 自定义404错误处理
app.UseStatusCodePages(async context =>
{
    // 检查状态码是否为404
    if (context.HttpContext.Response.StatusCode == (int)HttpStatusCode.NotFound)
    {
        // 可以自定义响应,比如返回JSON或者重定向到另一个页面
        //context.HttpContext.Response.ContentType = "text/plain";
        //await context.HttpContext.Response.WriteAsync("自定义的404错误信息");

        // 设置响应为200状态码,以隐藏404错误
        context.HttpContext.Response.StatusCode = (int)HttpStatusCode.OK;

        // 重定向到index.html
        context.HttpContext.Response.Redirect("index.html");
    }
});

app.UseAuthorization();

app.MapRazorPages();

app.Run();