将无效的 QueryStringParameter 重定向到 LinqDataSource
我有以下 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将“OnSelecting”方法名称添加到 LINQ 数据源,然后从该方法中检查您需要的任何内容:
Add an "OnSelecting" method name to your LINQ Data Source, then from that method, check for whatever you need: