开发者

Using codec file extensions with OpenRasta returns 404

When using codec uri file extensions with OpenRasta, OR can't resolve the uri and returns a 404. Without the file extension all works ok.

The 开发者_如何学Pythoncodecs are defined for the object resource and I'm using both XmlDataContract and JsonDataContract. Using neither the .xml or .json extension works, this is for both InMemoryHost (which we're using for testing) and ASP.Net (IIS7, integrated mode).

Codec configuration:

ResourceSpace.Has.ResourcesOfType<object>()
                .WithoutUri
                .AsXmlDataContract()
                .And.AsJsonDataContract();

Is there anything else that needs to be done to make uri file extensions work?


You need to register the ContentTypeExtensionUriDecorator as a UriDecorator in OpenRasta in order to expose the .xml, .json functionallity.

The below example should allow you to make http requests to:

GET /home.json

GET /home.xml

public class RastaConfig : IConfigurationSource
{
    public void Configure()
    {
        using(OpenRastaConfiguration.Manual)
        {
            ResourceSpace.Uses.UriDecorator<ContentTypeExtensionUriDecorator>();

            ResourceSpace.Has.ResourceOfType<Home>()
                .AtUri("/home")
                .HandledBy<HomeHandler>()
                .AsXmlDataContract()
                .And.AsJsonDataContract();
        }
    }
}

This is because noramlly the client will add an HTTP Accept header to define the content types it supports and is interested in.

For more information you can read about Content Negotiation (often referred to as conneg) on the web.

OpenRasta will then select the return content type based on the client 's preference in the HTTP Accept header.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜