i want to give an option to the page found on the home page search result feature to the gridview hyperlinkfield navigateUrl redirect to the desired page if the user is logged in and if not to redirect to the login/register page.i will be grateful if someone assist me how i do it.Thanks
i do not have much knowledge but i know some i know
<% if (Session["user"] == null) { %>
<li><a href="login.aspx">Login/Register</a></li>
<% } %>
and also i know
<asp:TemplateField HeaderText="Name" SortExpression="Name">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" Text='<%# eval("Name") %>' NavigateUrl='<%#"~/Pages/Topic.aspx?topicId=" + eval("topicId") %>' runat="server"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
You can assign ~/login.aspx
to navigateUrl
property in codeBehind ( gridView_ItemDataBound
handler) but it won't stop a user to type http://server.com/Pages/Topic.aspx?topicId=123
in address line and open the page.
Right solution is to check if user is logged in on that topic.aspx
page (in code behind) and redirect to login.aspx?returnUrl=/Pages/Topic.aspx?topicId=123
if necessary.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.