Content Type attribute

API Reference: ContentTypeAttribute Class

The ContentTypeAttribute can be applied to page models. The attribute specifies the content type value that is written in the Content-Type HTTP response header. Please note that it is your own responsibility to actually return content of the correct content type in the response. This can be done in the view.

Usage

Decorate the page model class with the ContentTypeAttribute. Pass the content type value in the attribute constructor. The attribute is not inherited, so if a content type is specified on a base class, it will not be automatically specified on derived classes.

Default Convention

If ContentTypeAttribute is not specified on a page model, text/html will be returned as the default content type in the HTTP response.

Example

[ContentType("application/rss+xml")]
public class RssFeed: IPageModel
{
    // ...
}

This example specifies the RSS content type for this page model.