fix(seo): proper 500 handler + safe JSON-LD escaping
CI/CD / CI · dotnet build (push) Successful in 45s
CI/CD / Deploy · drsousan (push) Successful in 25s

Add UseExceptionHandler(/error) so unhandled exceptions return a
proper HTML 500 instead of a raw response Googlebot was logging as
a server error in Search Console.

Replace manual quote-only escaping in blog JSON-LD with a J() helper
that uses JsonSerializer so newlines, backslashes, and all other
control characters are safely escaped.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
soroush.asadi
2026-06-19 09:01:45 +03:30
parent 82d9720e25
commit 5a1f1a8ccb
2 changed files with 25 additions and 5 deletions
+7 -5
View File
@@ -8,6 +8,8 @@
var articleType = ViewData["ArticleType"]?.ToString() ?? "MedicalWebPage";
var pubDate = post.PublishedAt?.ToString("yyyy-MM-ddTHH:mm:ssZ") ?? "";
var updDate = post.UpdatedAt.ToString("yyyy-MM-ddTHH:mm:ssZ");
// Escape a string for safe embedding inside a JSON string literal.
static string J(string? s) => System.Text.Json.JsonSerializer.Serialize(s ?? "")[1..^1];
}
@section Head {
@@ -32,13 +34,13 @@
<script type="application/ld+json">
{
"@@context": "https://schema.org",
"@@type": "@articleType",
"headline": "@post.Title.Replace("\"","\\\"") ",
"description": "@(ViewData["MetaDesc"]?.ToString()?.Replace("\"","\\\""))",
"author": { "@@type": "Person", "name": "@post.Author" },
"@@type": "@J(articleType)",
"headline": "@J(post.Title)",
"description": "@J(ViewData["MetaDesc"]?.ToString())",
"author": { "@@type": "Person", "name": "@J(post.Author)" },
"publisher": {
"@@type": "Organization",
"name": "@ViewData["SiteName"]",
"name": "@J(ViewData["SiteName"]?.ToString())",
"url": "@baseUrl"
},
"datePublished": "@pubDate",