Logout approach

Last post 09-18-2007 12:18 AM by maheshsingh. 6 replies.

Sort Posts:

  • Logout approach

    09-16-2007, 10:27 PM
    • Member
      314 point Member
    • rtortima
    • Member since 08-26-2006, 10:18 PM
    • Posts 419

    Hi, I am using a custom membershipProvider I have developed. Now I need to understand what would be the best approach for logging out. I wrote the code below in the Page_Load of my login.aspx:

    if (Context.User.Identity.IsAuthenticated){FormsAuthentication.SignOut();

    Session.Abandon();

    Session.Clear();}

    but I dont know if that is the best way to follow. Besides, I dont know the best way to hinder not authenticated users to type directly on the browser the mainPage.aspx and getting access to it...maybe I could put a code in Page_Load of mainPage.aspx, to test if user is authenticated, directing it to Login page if not. The code might be something like below:

     if (!Context.User.Identity.IsAuthenticated)

                   response.redirect("login.aspx");

    What do u guys think about it??? 

    Thanks a lot!!!!!

    We are here to learn, and teach whenever possible...
  • Re: Logout approach

    09-17-2007, 12:54 AM
    Answer
    • Participant
      1,039 point Participant
    • maheshsingh
    • Member since 07-28-2006, 8:23 AM
    • Noida, India
    • Posts 240

     Hi,

                 As per my thinking your logout approach is fine. For you login approach you can following web.config entry

    <system.web>
            <authentication mode="Forms">
                <forms loginUrl="~/SignIn.aspx"></forms>
            </authentication>
     </system.web>

    <configuration>
        <location path="Admin">
            <system.web>
                <authorization>
                    <allow roles="Admin"/>
                    <deny users="*"/>
                </authorization>
            </system.web>
        </location>
    </configuration>
     

    ------------------------------------------------------------------------------------
    Dont forget to click "Mark as Answer" on the post that helped you.
    ------------------------------------------------------------------------------------
    ~Mahesh

  • Re: Logout approach

    09-17-2007, 7:44 AM
    • Member
      314 point Member
    • rtortima
    • Member since 08-26-2006, 10:18 PM
    • Posts 419

    Well, then there is no configured way (in web.config for example) I can force not autenticathed users to go directly to login.aspx if they type a direct page, right?....I must place a specific code for that in each Load_Page of my webapp...correct?

    As for your config :

    <location path="Admin">
            <system.web>
                <authorization>
                    <allow roles="Admin"/>
                    <deny users="*"/>
                </authorization>
            </system.web>
        </location>

    I didnt quite understand, wouldnt that deny access to anyone, but admin user? besides I dont have role concept as default membership "understands", therefore I dont think that might apply to my case...

    Thanks again!!!

    Hope to keep hearing from you.

    We are here to learn, and teach whenever possible...
  • Re: Logout approach

    09-17-2007, 9:18 AM
    • Member
      314 point Member
    • rtortima
    • Member since 08-26-2006, 10:18 PM
    • Posts 419

    I also noticed a weird thing. When I click on SignOut button and its redirected to Login.aspx, if I type Main.aspx on the browser it goes back to the page, showing the loginname as if it were still logged in, but actually its not. Its like it was saved in a cache or something. If I do that in another browser, then it behaves accordingly, redirecting it to login.aspx (considering this new browser window does not have that "cache"). Is it normal ? How can I avoid it?

    Thanks again!

    We are here to learn, and teach whenever possible...
  • Re: Logout approach

    09-17-2007, 9:40 AM
    Answer
    • Participant
      1,039 point Participant
    • maheshsingh
    • Member since 07-28-2006, 8:23 AM
    • Noida, India
    • Posts 240

     Hi,

     If you don't have role kind of thing then also you can use web.config

    <location path="Admin">
            <system.web>
                <authorization>
                    <allow users="maheshs@brickred.com"/>
                    <deny users="*"/>
                </authorization>
            </system.web>
        </location>

    ------------------------------------------------------------------------------------
    Dont forget to click "Mark as Answer" on the post that helped you.
    ------------------------------------------------------------------------------------
    ~Mahesh

  • Re: Logout approach

    09-17-2007, 10:00 AM
    • Member
      314 point Member
    • rtortima
    • Member since 08-26-2006, 10:18 PM
    • Posts 419

    do u have a msn to talk about?

     

    We are here to learn, and teach whenever possible...
  • Re: Logout approach

    09-18-2007, 12:18 AM
    • Participant
      1,039 point Participant
    • maheshsingh
    • Member since 07-28-2006, 8:23 AM
    • Noida, India
    • Posts 240

     Hi,

              I am on yahoo: maheshsingh21@yahoo.co.in


     

    ------------------------------------------------------------------------------------
    Dont forget to click "Mark as Answer" on the post that helped you.
    ------------------------------------------------------------------------------------
    ~Mahesh

Page 1 of 1 (7 items)