From 599e57f443a0f8a4e92363a8110b91d119f2d7d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=94=E9=A3=9E=E7=9A=84=E9=A3=8E?= <27800734@qq.com> Date: Sun, 11 May 2025 02:32:05 +0000 Subject: [PATCH 01/15] =?UTF-8?q?=E5=88=A0=E9=99=A4CONTRIBUTING.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CONTRIBUTING.md | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 47ac404..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,40 +0,0 @@ -## Developer Certificate of Origin and License - -By contributing to GitLab B.V., you accept and agree to the following terms and -conditions for your present and future contributions submitted to GitLab B.V. -Except for the license granted herein to GitLab B.V. and recipients of software -distributed by GitLab B.V., you reserve all right, title, and interest in and to -your Contributions. - -All contributions are subject to the Developer Certificate of Origin and license set out at [docs.gitlab.com/ce/legal/developer_certificate_of_origin](https://docs.gitlab.com/ce/legal/developer_certificate_of_origin). - -_This notice should stay as the first item in the CONTRIBUTING.md file._ - -## Code of conduct - -As contributors and maintainers of this project, we pledge to respect all people -who contribute through reporting issues, posting feature requests, updating -documentation, submitting pull requests or patches, and other activities. - -We are committed to making participation in this project a harassment-free -experience for everyone, regardless of level of experience, gender, gender -identity and expression, sexual orientation, disability, personal appearance, -body size, race, ethnicity, age, or religion. - -Examples of unacceptable behavior by participants include the use of sexual -language or imagery, derogatory comments or personal attacks, trolling, public -or private harassment, insults, or other unprofessional conduct. - -Project maintainers have the right and responsibility to remove, edit, or reject -comments, commits, code, wiki edits, issues, and other contributions that are -not aligned to this Code of Conduct. Project maintainers who do not follow the -Code of Conduct may be removed from the project team. - -This code of conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. - -Instances of abusive, harassing, or otherwise unacceptable behavior can be -reported by emailing contact@gitlab.com. - -This Code of Conduct is adapted from the [Contributor Covenant](https://contributor-covenant.org), version 1.1.0, -available at [https://contributor-covenant.org/version/1/1/0/](https://contributor-covenant.org/version/1/1/0/). From cac57c2ca45f18461f67477b66ef8c90aca5e8e3 Mon Sep 17 00:00:00 2001 From: xiang <27800734@qq.com> Date: Sun, 11 May 2025 15:51:30 +0800 Subject: [PATCH 02/15] 1 --- README.md | 108 ++++++++++++++++-------------------------------------- 1 file changed, 31 insertions(+), 77 deletions(-) diff --git a/README.md b/README.md index c2b3744..09419b3 100644 --- a/README.md +++ b/README.md @@ -1,93 +1,47 @@ -# Yes.Blog +# Hyrule 开源博客系统说明文档 -## Getting started +## 概述 -To make it easy for you to get started with GitLab, here's a list of recommended next steps. +   Hyrule 是一个基于现代化技术栈构建的开源博客系统,采用简洁高效的架构设计,支持高度定制化开发。系统遵循CQRS模式,内置多数据库支持,并提供灵活的主题模板系统。 -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! +## 技术栈 -## Add your files +- [ ] 开发语言: C# (.NET 9.0) +- [ ] 核心框架: ASP.NET Core Minimal API +- [ ] 架构模式: CQRS with MediatR +- [ ] 模板引擎: Liquid +- [ ] 数据库支持:MySQL / SQL Server /PostgreSQL +- [ ] ORM: Entity Framework Core 9 +- [ ] 前端: 原生js + alpine -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: +## 功能特性 -``` -cd existing_repo -git remote add origin http://192.168.1.101:8080/yesblog/Yes.blog.git -git branch -M main -git push -uf origin main -``` +- [ ] 多用户博客管理 +- [ ] 文章/分类/标签系统 +- [ ] 评论与审核功能 +- [ ] SEO友好URL +- [ ] 自定义URL +- [ ] Markdown支持 +- [ ] 实时主题热重载 +- [ ] RESTful API +- [ ] 支持多种数据库 +- [ ] 支持多种文件存储方式 -## Integrate with your tools +## 快速开始 -- [ ] [Set up project integrations](http://192.1168.1.101/yesblog/Yes.blog/-/settings/integrations) +##环境要求 +- [ ] .NET SDK 9.0+ +- [ ] 支持的数据库任选其一 -## Collaborate with your team -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) -## Test and Deploy +## 许可证 + - MIT License -Use the built-in continuous integration in GitLab. + --- -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) +欢迎通过任何方式参与本项目! -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README - -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. \ No newline at end of file +如有疑问请通过 issues 或 discussions 与我们交流。 \ No newline at end of file From 9630aeace0d8f5681ce5f6ba43215e6c62205a6c Mon Sep 17 00:00:00 2001 From: xiang <27800734@qq.com> Date: Sun, 11 May 2025 16:12:46 +0800 Subject: [PATCH 03/15] 1 --- README.md | 65 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 09419b3..0597e44 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Hyrule 开源博客系统说明文档 +# Hyrule 开源博客系统 @@ -8,33 +8,56 @@ ## 技术栈 -- [ ] 开发语言: C# (.NET 9.0) -- [ ] 核心框架: ASP.NET Core Minimal API -- [ ] 架构模式: CQRS with MediatR -- [ ] 模板引擎: Liquid -- [ ] 数据库支持:MySQL / SQL Server /PostgreSQL -- [ ] ORM: Entity Framework Core 9 -- [ ] 前端: 原生js + alpine +- 开发语言: C# (.NET 9.0) +- 核心框架: ASP.NET Core Minimal API +- 架构模式: CQRS with MediatR +- 模板引擎: Liquid +- 数据库支持:MySQL / SQL Server /PostgreSQL +- ORM: Entity Framework Core +- 前端: 原生js + alpine ## 功能特性 -- [ ] 多用户博客管理 -- [ ] 文章/分类/标签系统 -- [ ] 评论与审核功能 -- [ ] SEO友好URL -- [ ] 自定义URL -- [ ] Markdown支持 -- [ ] 实时主题热重载 -- [ ] RESTful API -- [ ] 支持多种数据库 -- [ ] 支持多种文件存储方式 +- 多用户博客管理 +- 文章/分类/标签系统 +- 评论与审核功能 +- SEO友好URL +- 自定义URL +- Markdown支持 +- 实时主题热重载 +- RESTful API +- 支持多种数据库 +- 支持多种文件存储方式 ## 快速开始 -##环境要求 -- [ ] .NET SDK 9.0+ -- [ ] 支持的数据库任选其一 +#### 环境要求 +- .NET SDK 9.0+ +- 支持的数据库任选其一 +#### 部署方式 + +   推荐在linux系统通过docker方式一键部署 + +~~~ +docker run -e TZ=Asia/Shanghai -d --restart=always -v /data/hyrule:/app/files --name hyrule -p 8080:8080 registry.cn-guangzhou.aliyuncs.com/yescent/hyrule:latest +订单 + +~~~ + +#### 安装运行 +1. 安装后访问 http(s)://{domain}:8080 +2. 填写数据库连接信息安装 +3. 默认账号密码 admin / admin +4. 后台访问地址 http(s)://{domain}:8080/admin + + + + +#### 演示站点 + +- [https://hyrule.yescent.com](https://hyrule.yescent.com) +- 账号密码 test / test ## 许可证 From 051fa2bdaa42c012f46a009889a536a69de883f7 Mon Sep 17 00:00:00 2001 From: xiang <27800734@qq.com> Date: Sun, 11 May 2025 16:19:34 +0800 Subject: [PATCH 04/15] 1 --- README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0597e44..4d75bbe 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # Hyrule 开源博客系统 - - ## 概述    Hyrule 是一个基于现代化技术栈构建的开源博客系统,采用简洁高效的架构设计,支持高度定制化开发。系统遵循CQRS模式,内置多数据库支持,并提供灵活的主题模板系统。 @@ -21,7 +19,7 @@ - 多用户博客管理 - 文章/分类/标签系统 - 评论与审核功能 -- SEO友好URL +- SEO友好 - 自定义URL - Markdown支持 - 实时主题热重载 @@ -37,7 +35,7 @@ #### 部署方式 -   推荐在linux系统通过docker方式一键部署 +推荐在linux系统通过docker方式一键部署 ~~~ docker run -e TZ=Asia/Shanghai -d --restart=always -v /data/hyrule:/app/files --name hyrule -p 8080:8080 registry.cn-guangzhou.aliyuncs.com/yescent/hyrule:latest @@ -46,10 +44,11 @@ docker run -e TZ=Asia/Shanghai -d --restart=always -v /data/hyrule:/app/files -- ~~~ #### 安装运行 -1. 安装后访问 http(s)://{domain}:8080 + +1. 部署后访问 http(s)://{domain}:{port} 2. 填写数据库连接信息安装 3. 默认账号密码 admin / admin -4. 后台访问地址 http(s)://{domain}:8080/admin +4. 后台访问地址 http(s)://{domain}:{port}/admin @@ -61,7 +60,10 @@ docker run -e TZ=Asia/Shanghai -d --restart=always -v /data/hyrule:/app/files -- ## 许可证 - - MIT License + +- MIT License + + 您可以自由使用、修改和分发本项目的代码,但请保留原作者的版权声明和许可证信息。 --- From 2144dbaf43b973e2f4cca620caaed35baa15fbb5 Mon Sep 17 00:00:00 2001 From: xiang <27800734@qq.com> Date: Sun, 11 May 2025 16:20:07 +0800 Subject: [PATCH 05/15] 1 --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 4d75bbe..b12a4a1 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,6 @@ ~~~ docker run -e TZ=Asia/Shanghai -d --restart=always -v /data/hyrule:/app/files --name hyrule -p 8080:8080 registry.cn-guangzhou.aliyuncs.com/yescent/hyrule:latest -订单 ~~~ From 843069b6b9091f94fab385813138fa2d0133bb90 Mon Sep 17 00:00:00 2001 From: xiang <27800734@qq.com> Date: Sun, 11 May 2025 16:22:24 +0800 Subject: [PATCH 06/15] 1 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b12a4a1..cce212a 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ docker run -e TZ=Asia/Shanghai -d --restart=always -v /data/hyrule:/app/files -- #### 安装运行 1. 部署后访问 http(s)://{domain}:{port} -2. 填写数据库连接信息安装 +2. 填写数据库连接信息安装,此时将自动创建数据库 3. 默认账号密码 admin / admin 4. 后台访问地址 http(s)://{domain}:{port}/admin From b901a1f63af05e0465ce799bcfc9a4e38a52f6f6 Mon Sep 17 00:00:00 2001 From: xiang <27800734@qq.com> Date: Sun, 11 May 2025 16:23:50 +0800 Subject: [PATCH 07/15] 1 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index cce212a..d3da970 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ docker run -e TZ=Asia/Shanghai -d --restart=always -v /data/hyrule:/app/files -- - 账号密码 test / test + ## 许可证 - MIT License From 72fc426b257fbd16e860351b8cc6388413bfc50a Mon Sep 17 00:00:00 2001 From: xiang <27800734@qq.com> Date: Sun, 11 May 2025 16:25:20 +0800 Subject: [PATCH 08/15] 1 --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d3da970..bb1c38e 100644 --- a/README.md +++ b/README.md @@ -60,11 +60,14 @@ docker run -e TZ=Asia/Shanghai -d --restart=always -v /data/hyrule:/app/files -- ## 许可证 - -- MIT License + - MIT License 您可以自由使用、修改和分发本项目的代码,但请保留原作者的版权声明和许可证信息。 + + + + --- 欢迎通过任何方式参与本项目! From aca300d72393c2a29a2abb9ba4dfa0f969365045 Mon Sep 17 00:00:00 2001 From: xiang <27800734@qq.com> Date: Sun, 11 May 2025 16:37:33 +0800 Subject: [PATCH 09/15] 1 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bb1c38e..ffb212a 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ docker run -e TZ=Asia/Shanghai -d --restart=always -v /data/hyrule:/app/files -- #### 演示站点 - [https://hyrule.yescent.com](https://hyrule.yescent.com) +- 后台 [https://hyrule.yescent.com/admin)](https://hyrule.yescent.com/admin) - 账号密码 test / test From 8206cfa9b1f3203b782db9a78ec77c523a86493a Mon Sep 17 00:00:00 2001 From: xiang <27800734@qq.com> Date: Sun, 11 May 2025 16:39:01 +0800 Subject: [PATCH 10/15] 1 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ffb212a..7e22e01 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ docker run -e TZ=Asia/Shanghai -d --restart=always -v /data/hyrule:/app/files -- #### 演示站点 - [https://hyrule.yescent.com](https://hyrule.yescent.com) -- 后台 [https://hyrule.yescent.com/admin)](https://hyrule.yescent.com/admin) +- 后台 [https://hyrule.yescent.com/admin](https://hyrule.yescent.com/admin) - 账号密码 test / test From c91a69e64125d52833d7587c00198641460b7c06 Mon Sep 17 00:00:00 2001 From: xiang <27800734@qq.com> Date: Sun, 11 May 2025 16:51:41 +0800 Subject: [PATCH 11/15] 1 --- .gitlab-ci.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index eedfcc5..7f99d31 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,6 +2,7 @@ stages: - check - build - deploy + - sync variables: DockerfilePath: "./${ProjectName}/Dockerfile" @@ -9,6 +10,26 @@ variables: MasterDockerImage: "${Ali_Docker_Registry}/${Namespace}/${MasterPackageName}" +# sync_to_github: +# stage: sync +# image: alpine/git +# script: +# - git config --global user.email "ci@example.com" +# - git config --global user.name "GitLab CI" +# - git remote add github https://oauth2:${GITHUB_TOKEN}@github.com/8720826/Hyrule.git +# - git push github --all +# - git push github --tags + +sync_to_gitee: + stage: sync + image: alpine/git + script: + - git config --global user.email "ci@example.com" + - git config --global user.name "GitLab CI" + - git remote add gitee https://oauth2:${GITEE_TOKEN}@gitee.com/username/project.git + - git push gitee --all + - git push gitee --tags + check-merge-target: stage: check script: From f7761c2c190dd98019d54dea47d70f6caff9ef75 Mon Sep 17 00:00:00 2001 From: xiang <27800734@qq.com> Date: Sun, 11 May 2025 16:52:13 +0800 Subject: [PATCH 12/15] 1 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7f99d31..e4685fc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -26,7 +26,7 @@ sync_to_gitee: script: - git config --global user.email "ci@example.com" - git config --global user.name "GitLab CI" - - git remote add gitee https://oauth2:${GITEE_TOKEN}@gitee.com/username/project.git + - git remote add gitee https://oauth2:${GITEE_TOKEN}@gitee.com/q8720826/Hyrule.git - git push gitee --all - git push gitee --tags From d92a32f56757f9ba7ba8099e838959d4b1acd0b7 Mon Sep 17 00:00:00 2001 From: xiang <27800734@qq.com> Date: Sun, 11 May 2025 17:03:33 +0800 Subject: [PATCH 13/15] 1 --- .gitlab-ci.yml | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e4685fc..1335d74 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,15 +10,15 @@ variables: MasterDockerImage: "${Ali_Docker_Registry}/${Namespace}/${MasterPackageName}" -# sync_to_github: -# stage: sync -# image: alpine/git -# script: -# - git config --global user.email "ci@example.com" -# - git config --global user.name "GitLab CI" -# - git remote add github https://oauth2:${GITHUB_TOKEN}@github.com/8720826/Hyrule.git -# - git push github --all -# - git push github --tags +sync_to_github: + stage: sync + image: alpine/git + script: + - git config --global user.email "ci@example.com" + - git config --global user.name "GitLab CI" + - git remote add github https://oauth2:${GITHUB_TOKEN}@github.com/8720826/Hyrule.git + - git push github --all + - git push github --tags sync_to_gitee: stage: sync @@ -26,9 +26,12 @@ sync_to_gitee: script: - git config --global user.email "ci@example.com" - git config --global user.name "GitLab CI" - - git remote add gitee https://oauth2:${GITEE_TOKEN}@gitee.com/q8720826/Hyrule.git + - git remote add gitee https://oauth2:${GITEE_TOKEN}@gitee.com/q8720826/hyrule.git - git push gitee --all - git push gitee --tags + only: + - master + check-merge-target: stage: check From 992721b280d5cfea1faf3c5a1ae440d1ffb1fe33 Mon Sep 17 00:00:00 2001 From: xiang <27800734@qq.com> Date: Sun, 11 May 2025 17:35:16 +0800 Subject: [PATCH 14/15] 1 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1335d74..840512c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,7 +16,7 @@ sync_to_github: script: - git config --global user.email "ci@example.com" - git config --global user.name "GitLab CI" - - git remote add github https://oauth2:${GITHUB_TOKEN}@github.com/8720826/Hyrule.git + - git remote add github https://oauth2:${GITHUB_TOKEN}@github.com/8720826/hyrule.git - git push github --all - git push github --tags From e2f75fb4ddce69f361c533a6f4bd55d85b2eeae3 Mon Sep 17 00:00:00 2001 From: xiang <27800734@qq.com> Date: Sun, 11 May 2025 17:40:51 +0800 Subject: [PATCH 15/15] 1 --- .../GlobalExceptionHandlerMiddleware.cs | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/Yes.Infrastructure/Middlewares/GlobalExceptionHandlerMiddleware.cs b/Yes.Infrastructure/Middlewares/GlobalExceptionHandlerMiddleware.cs index 09f3aa9..eb18af6 100644 --- a/Yes.Infrastructure/Middlewares/GlobalExceptionHandlerMiddleware.cs +++ b/Yes.Infrastructure/Middlewares/GlobalExceptionHandlerMiddleware.cs @@ -19,8 +19,12 @@ private async Task HandleExceptionAsync(HttpContext context, Exception ex) { - context.Response.ContentType = "application/problem+json"; - context.Response.StatusCode = StatusCodes.Status500InternalServerError; + if (!context.Response.HasStarted) + { + context.Response.ContentType = "application/problem+json"; + context.Response.StatusCode = StatusCodes.Status500InternalServerError; + } + var title = ""; var message = ""; var exType = ex.GetType(); @@ -50,22 +54,25 @@ _logger.LogError(ex, "Exception"); } - var acceptHeader = context.Request.Headers["Accept"].FirstOrDefault(); - var isAjaxRequest = acceptHeader?.Contains("application/json") == true; - if (isAjaxRequest) + if (!context.Response.HasStarted) { - var problem = new ProblemDetails + var acceptHeader = context.Request.Headers["Accept"].FirstOrDefault(); + var isAjaxRequest = acceptHeader?.Contains("application/json") == true; + if (isAjaxRequest) { - Status = StatusCodes.Status500InternalServerError, - Title = title, - Type = "https://tools.ietf.org/html/rfc7231#section-6.5.1", - Detail = message - }; - await context.Response.WriteAsJsonAsync(problem); - } - else - { - await context.Response.WriteAsync(message); + var problem = new ProblemDetails + { + Status = StatusCodes.Status500InternalServerError, + Title = title, + Type = "https://tools.ietf.org/html/rfc7231#section-6.5.1", + Detail = message + }; + await context.Response.WriteAsJsonAsync(problem); + } + else + { + await context.Response.WriteAsync(message); + } } }