跳到主要內容

發表文章

目前顯示的是有「SEO」標籤的文章

使用 RobotsTxtCore 建立 robot.txt & sitemap.xml

Nuget Link 透過 nuget 安裝 RobotsTxtCore >dotnet add package RobotsTxtCore --version 1.1.0 //Startup.cs public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { ... app.UseRobotsTxt(builder =>builder .AddSection(section => section .AddComment("Allow Googlebot") .AddUserAgent("Googlebot") .AddUserAgent("Googlebot-News") .AddUserAgent("Googlebot-Image") .AddUserAgent("Googlebot-Mobile") .AddUserAgent("Googlebot-Video") .AddUserAgent("Mediapartners-Google") .AddUserAgent("Adsbot-Google") .Allow("/") ) .AddSection(section => section .AddComment("Disallow the rest") .AddUserAgent("*") .AddCrawlDelay(TimeSpan.FromSeconds(10)) .Disallow("/") ) .AddSitemap("https://${domain}/sitemap.xml") ); }

meta tag 說明

meta tag 說明 1. <title></title> *建議中文保持在 30 個字元、英文 60 個字元以內 *可以用以下格式: 主要關鍵字  -  次要關鍵字 | 廠牌名稱 *每個頁面的 Title 都是唯一的 <title>MyDemo-@ViewData["Title"]</title> 2. <meta name='description' content='@ViewData["PageDescript"]' /> *建議中文保持在 80 個字元、英文 160 個字元以內 3. og 社群相關 tag og 全名為: Open Graph Protocol *在 og:title 設定的文字會當作分享 FB 時的標題。 3.1 og:image *大小不要超過 8 m *尺寸要大於 200px * 200px,否則連圖都抓不到 *如果圖片為長方形 建議最小尺寸 600px * 315px *如果圖片為正方形 建議最小尺寸 600px * 600px 程式化新增 meta tag //在DotNet Core Project中 新增目錄夾 Filters ,並新增MetaTagFilter.cs 檔案 using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc; namespace WebProject.Filters { public class MetaTagAttribute : TypeFilterAttribute { public MetaTagAttribute( ) : base( typeof( MetaTagFilter ) ) { } public class MetaTagFilter : IActionFilter { private string title { get; set; } private string des...