Posted by Max | Posted in asp.net | Posted on 02-02-2009
0
If you need to generate a datetime value for RSS feed you need to use RFC-822 format for dates. You can do it the following Extension method:
public static string ToRFC822String(this DateTime date)
{
return date.ToString("ddd, dd MMM yyyy HH:mm:ss ") +
date.ToString("zzzz").Replace(":", String.Empty);
}
Posted by Max | Posted in asp.net | Posted on 25-01-2008
3
RadGrid GridBoundColumn values are not HTML encoded by default (see screenshot), so there is a risk of cross site scripting attack.

Extract from code behind:
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
string[] str =
new string[] {
-
"test <h1>string</h1>"
-
};
-
-
radGrid.DataSource = str;
-
radGrid.DataBind();
-
-
GridView1.DataSource = str;
-
GridView1.DataBind();
-
}
There is no Html encode option available at this moment so the best you can do is to encode values with ItemDataBound event:
-
protected void RadGrid1_ItemDataBound(object sender, Telerik.WebControls.GridItemEventArgs e)
-
{
-
if (e.
Item is GridDataItem
)
-
{
-
GridDataItem item = e.Item as GridDataItem;
-
item["Content"].Text = Server.HtmlEncode(item["Content"].Text);
-
}
-
}
More information about this on Telerik support forum.
Another option is to create new new class which inherits from RadGrid column (e.g. GridBoundColumn) and override its PrepareCell method:
ASPX page:
-
<rad:RadGrid ID="radGrid" runat="server">
-
<MasterTableView GridLines="Vertical" AutoGenerateColumns="False">
-
<Columns>
-
<wt:MyGridBoundColumn DataField="Field1" UniqueName="Field1" HeaderText="Field1" />
-
</Columns>
-
</MasterTableView>
-
</rad:RadGrid>
Code behind:
-
public class MyGridBoundColumn : Telerik.WebControls.GridBoundColumn
-
{
-
private bool _htmlEncode = true;
-
-
public bool HtmlEncode
-
{
-
get { return _htmlEncode; }
-
set { _htmlEncode = value; }
-
}
-
-
public override void PrepareCell(
-
TableCell cell,
-
Telerik.WebControls.GridItem item
-
)
-
{
-
base.PrepareCell(cell, item);
-
if (_htmlEncode)
-
{
-
cell.Text = HttpUtility.HtmlEncode(
-
cell.Text
-
);
-
}
-
}
-
}
-