Using codec file extensions with OpenRasta returns 404

丶灬走出姿态 提交于 2019-12-03 21:45:21

问题


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 codecs 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?


回答1:


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.



来源:https://stackoverflow.com/questions/4956103/using-codec-file-extensions-with-openrasta-returns-404

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!