Using codec file extensions with OpenRasta returns 404

前端 未结 1 1003
萌比男神i
萌比男神i 2021-01-06 20:42

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

相关标签:
1条回答
  • 2021-01-06 21:06

    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 讨论(0)
提交回复
热议问题