Nuget Link
透過 nuget 安裝 RobotsTxtCore
透過 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")
);
}
留言
張貼留言