locked
Guestbook or any other tab/link made invisible unless logged in? RRS feed

  • Question

  • User-2010712463 posted

    Does anyone know how difficult it would be to make one of the tab's or links invisible unless someone is logged in?  I'm using JW's extended kit and am building a video page I would only like visible to people who have a resistered username and password.

    Thanks!

    Sunday, December 9, 2007 3:40 PM

Answers

  • User2069888697 posted

    I never tried that version but,

    If the link is coming from the sitemap you can add this to the web.config

    	<location path="PAGENAME.aspx">
    		<system.web>
    			<authorization>
    				<deny users="?"/>
    			</authorization>
    		</system.web>
    	</location>

     If it is a link you added to the page use a Page Load event, of course set the default value to false and add a Page Load event on the restricted page to redirect unauthenticated users if they try to type the url in the address bar.

     
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            If User.Identity.IsAuthenticated = True Then
                LinkButton1.visible = True
            End If
    End Sub
     
      
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            If User.Identity.IsAuthenticated = false Then
                Response.Redirect("Deault.aspx")
            End If
    End Sub
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 9, 2007 6:38 PM

All replies

  • User2069888697 posted

    I never tried that version but,

    If the link is coming from the sitemap you can add this to the web.config

    	<location path="PAGENAME.aspx">
    		<system.web>
    			<authorization>
    				<deny users="?"/>
    			</authorization>
    		</system.web>
    	</location>

     If it is a link you added to the page use a Page Load event, of course set the default value to false and add a Page Load event on the restricted page to redirect unauthenticated users if they try to type the url in the address bar.

     
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            If User.Identity.IsAuthenticated = True Then
                LinkButton1.visible = True
            End If
    End Sub
     
      
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            If User.Identity.IsAuthenticated = false Then
                Response.Redirect("Deault.aspx")
            End If
    End Sub
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 9, 2007 6:38 PM
  • User-2010712463 posted

    The changes you suggested to the web.config file worked perfectly.  That was easy!

    Thanks

    Monday, December 10, 2007 6:55 PM
  • User76383614 posted

    First, excuse my lack of knowledge - I'm very new to ASP.NET.

    I have implemented this solution exactly as detailed and have two problems with it.

    1) If I try to access "RestrictedPage.aspx" by typing in the URL, without logging in first, I get redirected to the login page, not the Default page. 

    2) If I login, and then logout and then try to access "RestrictedPage.aspx" by typing in the URL, I get access to the page, showing I'm still logged in.

    Any suggestions ?

    TIA,

    Mike

     

     

     

    Friday, December 14, 2007 6:36 AM
  • User2069888697 posted

    The redirect to the login page is done by the Web.config option.  Ideally that is where the second option should redirect also I just put default.(misspelled by the way) If using the Web.config option you do not need the Page load option.

    The second issue is comming from the temporary internet files, it is not a cookie issue as I tried clearing just cookies and that did not solve it, but when I clear Temporary Internet files( through the options menu in IE7) it does.

    Friday, December 14, 2007 10:42 AM