Usability, MVC, ASP.NET

31. March 2011 01:06
by Henrik Stenbæk
0 Comments

Dynamic robots.txt with ASP.NET MVC

31. March 2011 01:06 by Henrik Stenbæk | 0 Comments

If you have one application on your IIS and several domain names pointing to it, it’s possible to have different robots.txt files served based on the current domain name.

1. Add a route

CropperCapture[1]

2. Create the RobotsController

CropperCapture[2]

3. The SeoHelper just implements a simple way of determine what robots.txt file to return

CropperCapture[3]

4. Add the different versions of the robot.txt to the site root – remark the content for the robots.txt could be served from any source, I have just chosen a simple model to keep it simple

CropperCapture[4]

5. Run the site and request robots.txt

CropperCapture[5]

CropperCapture[6]

Get the source code: DynamicRobotsTxt.rar (21,66 kb)

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading