The JsonFeed tag, first introduced in version 4.3, is used to easily generate JSON output from your data. JSON is the lingua franca of client-server communication these days and many Javascript and jQuery plugins natively consume it. You could create a JSON feed using the standard feed tag, but the JsonFeed tag saves you a lot of typing. There may still be times when you want to use special layouts or formatting in your feed that you'll want to use the Feed tag, but in most situations, the JsonFeed is all you need.
Creating a feed is a two-step process:
It's important to note that feeds, by their nature, are typically intended to be public. No special security measures have been implemented for securing the feed. So you should be careful about what data you make available through a feed. One way you could make your feed more secure is by creating and passing a token to the feed. This token would then be checked by your data source (most likely a stored procedure) to determine its validity, returning the data only if it's valid.
<xmod:feed
Doctype="string"
ContentType="string"
ConnectionString="string"
Filename="string"
ViewRoles="role1,role2,role3">
<ListDataSource CommandText="string"
ConnectionString="string"/>
<HeaderTemplate>...</HeaderTemplate>
<ItemTemplate>...</ItemTemplate>
<AlternatingItemTemplate>...</AlternatingItemTemplate>
<SeparatorTemplate>...</SeparatorTemplate>
<FooterTemplate>...</FooterTemplate>
</xmod:feed>
SELECT
command or a stored procedure. Supply the SQL command as the CommandText attribute. For stored procedures, use EXEC sprocName
. Note that Bit columns are returned as True/False - not 1/0. The data source for a feed is defined in the <ListDataSource>
tag. ListDataSource: Provides the data for the feed when it is rendering. It accepts <parameter> tags to pass parameters as part of the command. The "alias" attribute is optional and is used to avoid conflicts or to accept a parameter with a specific name (the "name" attribute) but use a different parameter name in the command (the "alias" attribute). If no "alias" is specified, the "name" will be used.
Examples:
#1 <ListDataSource CommandText="SELECT FirstName, LastName FROM Users" />
#2 <ListDataSource CommandText="SELECT FirstName, LastName FROM Users WHERE ZipCode = @zip"> <Parameter Name="zip" value='[[Url:zip]]' /> </ListDataSource>
#3 <ListDataSource CommandText="EXEC GetUsers @zip"> <Parameter Name="zip" value="12345" /> </ListDataSource>
You can optionally specify a ConnectionString for this data source. If none is specified, the default connection will be used he current DotNetNuke database if the tag doesn't define a connection. As with the template tag, you can use the [[ConnectionString:connectionName]]
token to use a connection defined in the web.config file.
<xmod:JsonFeed>
<ListDataSource CommandText="SELECT [AuthorId], [FirstName], [LastName], [GenreId] FROM Authors WHERE GenreId = @gid"> <Parameter Name="gid" Value='[[Url:genre]]' DataType="Int32" DefaultValue="-1" /> </ListDataSource>
</xmod:JsonFeed>