2

In OpenRasta, how am I supposed to register resources with three different codecs and access these codecs through a regular web browser by appending an extension to the URL? The following doesn't seem to work:

MediaType json = MediaType.Json.WithQuality(1f);
MediaType xml = MediaType.Xml.WithQuality(0.9f);
MediaType html = MediaType.Html.WithQuality(0.1f);

ResourceSpace.Has
    .ResourcesOfType<ResourceBase>()
    .WithoutUri
    .TranscodedBy<MyXmlCodec>().ForMediaType(xml).ForExtension("xml")
    .And.TranscodedBy<MyHtmlCodec>().ForMediaType(html).ForExtension("html")
    .And.TranscodedBy<JsonDataContractCodec>().ForMediaType(json).ForExtension("json");

ResourceSpace.Has
    // UserListResource inherits ResourceBase
    .ResourcesOfType<UserListResource>()
    .AtUri("/users")
    .HandledBy<UserHandler>();

UserListResource is registered and made available as text/html in a regular web browser, but appending .xml to the URL just gives me a 404. I've tried this:

ResourceSpace.Has
    // UserListResource inherits ResourceBase
    .ResourcesOfType<UserListResource>()
    .AtUri("/users")
    .And.AtUri("/users.xml")
    .HandledBy<UserHandler>();

But that only gives me the same text/html representation on both /users and /users.xml.

Asbjørn Ulsberg
  • 8,721
  • 3
  • 45
  • 61
  • 1
    See my other answer here: http://stackoverflow.com/a/4960008/59816 – Psiren Aug 03 '12 at 13:49
  • @ScottLittlewood, I can't get the `ContentTypeExtensionUriDecorator` to work. Adding it doesn't really make any difference to my app; requesting any URI with `.xml` suffixed just results in a 404. Ideas? – Asbjørn Ulsberg Sep 10 '12 at 13:54

0 Answers0