fix(seo): proper 500 handler + safe JSON-LD escaping
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:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user