首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在无效的QueryStringParameter上重定向到LinqDataSource

在无效的QueryStringParameter上重定向到LinqDataSource
EN

Stack Overflow用户
提问于 2011-06-20 16:21:50
回答 1查看 318关注 0票数 0

我有以下LinqDataSource:

代码语言:javascript
复制
<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时,用户才应该被重定向。当数据源不包含任何行时,应该始终发生这种情况。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-18 23:20:59

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

代码语言:javascript
复制
<asp:LinqDataSource runat="server" OnSelecting="ldsSelecting" .... />

protected void ldsSelecting(object o, LinqDataSourceSelectEventArgs e)
{
     // check for query string or other stuff here, redirect if needed
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6408503

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档