怪奇物语

怪奇物语

首页 新随笔 联系 管理

安全证书到期 asp.net vue

此服务器无法证明它是 localhost;它的安全证书已于 5 天前到期。这可能是错误配置或攻击者截获连接而导致。计算机的时钟当前设置为 2025年4月28日星期一。显示的时间是否正确?如果不正确,则应更正系统时钟,然后刷新此页面。

背景

新建了一个asp.net的web page的程序,后来发现证书到期,无法访问前端网页,报错如下:

此服务器无法证明它是 localhost;它的安全证书已于 5 天前到期。这可能是错误配置或攻击者截获连接而导致。计算机的时钟当前设置为 2025年4月28日星期一。显示的时间是否正确?如果不正确,则应更正系统时钟,然后刷新此页面。
import { fileURLToPath, URL } from 'node:url';
import { defineConfig } from 'vite';
import plugin from '@vitejs/plugin-vue';
import fs from 'fs';
import path from 'path';
import child_process from 'child_process';
import { env } from 'process';
import tailwindcss from '@tailwindcss/vite';

const baseFolder =
    env.APPDATA !== undefined && env.APPDATA !== ''
        ? `${env.APPDATA}/ASP.NET/https`
        : `${env.HOME}/.aspnet/https`;

const certificateName = "longforcecocweb.client";
const certFilePath = path.join(baseFolder, `${certificateName}.pem`);
const keyFilePath = path.join(baseFolder, `${certificateName}.key`);

if (!fs.existsSync(certFilePath) || !fs.existsSync(keyFilePath)) {
    if (0 !== child_process.spawnSync('dotnet', [
        'dev-certs',
        'https',
        '--export-path',
        certFilePath,
        '--format',
        'Pem',
        '--no-password',
    ], { stdio: 'inherit', }).status) {
        throw new Error("Could not create certificate.");
    }
}

const target = env.ASPNETCORE_HTTPS_PORT ? `https://localhost:${env.ASPNETCORE_HTTPS_PORT}` :
    env.ASPNETCORE_URLS ? env.ASPNETCORE_URLS.split(';')[0] : 'https://localhost:5001';

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [plugin(),tailwindcss()],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        }
    },
    server: {
        proxy: {

            '^/weatherforecast': {
                target,
                secure: false
            }
        },
        port: 5173,
        https: {
            key: fs.readFileSync(keyFilePath),
            cert: fs.readFileSync(certFilePath),
        }
    }
})


解决方案

进入到如下的文件夹中,删除对应的证书文件,即可,会自动重新生成

C:\Users\{User}\AppData\Roaming\ASP.NET\https
posted on 2025-04-29 08:00  超级无敌美少男战士  阅读(23)  评论(0)    收藏  举报