Prevent control of data binding to ObjectDataSource?

I have a page that expects a numeric query string value. For instance:

Details.aspx?rgn=1234

      

This page contains the <asp:repeater>

anchored to the <asp:objectdatasource>

. The data source looks something like this:

<asp:ObjectDataSource ID="ObjectRegion" runat="server" SelectMethod="GetRegions" TypeName="Region">
  <SelectParameters>
    <asp:QueryStringParameter Name="RegionID" QueryStringField="rgn" Type="Int32" DefaultValue='0' />
  </SelectParameters>
</asp:ObjectDataSource>

      

Since this is a public page, sometimes I get non-numeric value by hackers / search engines / nosy people. I check this in my Page_Load. Something like that:

protected void Page_Load(object sender, EventArgs e)
{
    int RegionID;
    string strRegion = Request.QueryString["rgn"];
    if(string.IsNullOrEmpty(strRegion) || !int.TryParse(strRegion, out RegionID))
    {
        // setup permanent redirect
        return;
    }
}

      

The problem is that my relay is doing data binding anyway, which is causing [FormatException: Input string was not in a correct format.]

... which is what I want to prevent. Any ideas for an easy way to get around this?

0


a source to share


1 answer


I answered my own question. I forgot to add Response.End()

to the permanent redirect:



Response.Status = "301 Moved Permanently";
Response.AddHeader("Location",URL);
Response.End();

      

0


a source







All Articles