将无效的 QueryStringParameter 重定向到 LinqDataSource

发布于 2024-11-16 08:47:22 字数 883 浏览 3 评论 0原文

我有以下 LinqDataSource:

<asp:LinqDataSource ID = "agreementDs"
                    ContextTypeName = "AdministrationDataContext"
                    TableName = "Agreements"
                    runat = "server"
                    EnableUpdate = "true"                        
                    Where = "AgreementId=@AgreementId">

    <WhereParameters>
        <asp:QueryStringParameter QueryStringField = "AgreementId" 
                                  Name = "AgreementId"
                                  Type = "Int32"
                                  DefaultValue = "-1" />
    </WhereParameters>                        
</asp:LinqDataSource>    

它应该从协议数据库表中获取一行。如何检测参数AgreementId是否为-1,如果是,则提供404页面或将用户重定向到我的网站的首页?我无法弄清楚在代码隐藏中插入此逻辑的正确位置是什么。

更新:不仅仅是当AgreementId 参数为-1 时才应重定向用户。当数据源不包含任何行时,它应该总是发生。

I have the following LinqDataSource:

<asp:LinqDataSource ID = "agreementDs"
                    ContextTypeName = "AdministrationDataContext"
                    TableName = "Agreements"
                    runat = "server"
                    EnableUpdate = "true"                        
                    Where = "AgreementId=@AgreementId">

    <WhereParameters>
        <asp:QueryStringParameter QueryStringField = "AgreementId" 
                                  Name = "AgreementId"
                                  Type = "Int32"
                                  DefaultValue = "-1" />
    </WhereParameters>                        
</asp:LinqDataSource>    

It is supposed to fetch one row from the agreements database table. How can I detect if the parameter AgreementId is -1 and if so either serve up a 404 page or redirect the user to the front page of my site? I cant figure out what the correct place is to insert this logic in the code-behind.

Update: It is not only when the AgreementId parameter is -1 that the user should be redirected. It should always happen when the data source does not contain any rows.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怀里藏娇 2024-11-23 08:47:22

将“OnSelecting”方法名称添加到 LINQ 数据源,然后从该方法中检查您需要的任何内容:

<asp:LinqDataSource runat="server" OnSelecting="ldsSelecting" .... />

protected void ldsSelecting(object o, LinqDataSourceSelectEventArgs e)
{
     // check for query string or other stuff here, redirect if needed
}

Add an "OnSelecting" method name to your LINQ Data Source, then from that method, check for whatever you need:

<asp:LinqDataSource runat="server" OnSelecting="ldsSelecting" .... />

protected void ldsSelecting(object o, LinqDataSourceSelectEventArgs e)
{
     // check for query string or other stuff here, redirect if needed
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文