1

Basically I am trying to use the new MVC5 routing attribute to redirect /sitemap.xml to a method as I need to dynamically create it.

// GET: /sitemap.xml
[Route("sitemap.xml")]
public ActionResult SiteMap()
{
    // Stuff
}

At the moment that doesn't work so is it possible to do it like this or will I have to use the routing table like I did before?

routes.MapRoute(
   name: "Site Map",
   url: "sitemap.xml",
   defaults: new { controller = "Default", action = "SiteMap" });
4
  • 1
    stackoverflow.com/questions/16886093/… Commented Jan 19, 2014 at 13:02
  • I've already got that added Commented Jan 19, 2014 at 13:14
  • Well I've used that before with the correct result. You could try that runAllManagedHandlers flag to troubleshoot. If that doesn't work then something's weird somewhere. Commented Jan 19, 2014 at 13:20
  • I don't suppose you have a route prefix at the controller level so it's not /sitemap.xml but /abcd/sitemap.xml ? Commented Jan 19, 2014 at 13:21

1 Answer 1

2

Add this to your web.config:

 <system.webServer>
 <handlers>
      <add name="ManagedDllExtension" path="*.xml" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
</system.webServer>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.