Last active
June 29, 2022 19:49
-
-
Save carlin-q-scott/08a8c3341b0ee85a9ffd350ba51ae056 to your computer and use it in GitHub Desktop.
robots.txt Razor Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@page "/robots.txt" | |
@{ | |
Layout = null; | |
Response.ContentType = "text/plain"; | |
} | |
@using Microsoft.AspNetCore.Hosting | |
@inject IHostingEnvironment env | |
User-agent: * | |
@if (env.IsProduction()) | |
{ | |
@Html.Raw("Disallow: /hidden/path"); | |
} | |
else | |
{ | |
@Html.Raw("Disallow: /"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This Razor Page will generate a robots.txt for your ASP.NET website. By default it will hide the whole site from web crawlers if it's not production. To use this file, put it in the Pages folder inside your ASP.NET project, and modify the Html.Raws accordingly.