Results 1 to 8 of 8

Thread: Load event

  1. #1
    Join Date
    Jul 2006
    Posts
    276
    Rep Power
    0

    Default Load event

    I have a big problem guys in asp.net, i need the code in the load event on a page to trigger everytime its loaded. The problem is for example i have a user called nas, and nas logs in and chooses to view his information, when he logs out and a different user say chris when he selects to view his information he sees nas's information. This occurs because the code that does all the binding is on the load event of the page. And because the page was already called instead of it running the code again it receives the page from cache. Now the question is: Is their any way to prevent this from happening and cuz the code on the load event to run again?

    Need urgent help!
    The greatest discovery of all men through lifetime is that a man can alter his life by altering his attitude!

  2. #2
    Join Date
    Dec 2004
    Posts
    1,181
    Rep Power
    0

    Default

    Provide some code so we can have a better understanding of how you implementing this. If you are using forms authentication, you should not be having this problem.
    'If we're supposed to work in Hex, why have we only got A fingers?'

    Follow Me: @psybuck2002us

  3. #3
    Join Date
    Dec 2002
    Posts
    500
    Rep Power
    0

    Default

    you can configure caching to work with parameters, or using page directives... i dont remember it exactly but you can consult any asp.net book, it should be in the first few (overview) pages.

    maybe i'll find it tomorrow and tell you, if no one else helps out by then.
    Cultured in Aggression and Koding like a Warrior!!
    “Common sense is instinct. Enough of it is genius.” - George Bernard Shaw.
    "The significant problems we face cannot be solved by the same level of thinking that created them." - Albert Einstein

  4. #4
    Join Date
    Feb 2005
    Posts
    85
    Rep Power
    0

    Default

    Quote Originally Posted by norminator View Post
    This occurs because the code that does all the binding is on the load event of the page. And because the page was already called instead of it running the code again it receives the page from cache. Now the question is: Is their any way to prevent this from happening and cuz the code on the load event to run again?

    Need urgent help!
    This code will prevent IE browsers from caching:

    Response.CacheControl = "no-cache"
    Response.AddHeader "Pragma", "no-cache"
    Response.Expires = -1

    OR

    Response.Cache.SetCacheability(HttpCacheability.No Cache)


    This code will prevent All browsers from caching:

    Response.ClearHeaders()
    Response.AppendHeader("Cache-Control", "no-cache")
    Response.AppendHeader("Cache-Control", "private")
    Response.AppendHeader("Cache-Control", "no-store")
    Response.AppendHeader("Cache-Control", "must-revalidate")
    Response.AppendHeader("Cache-Control", "max-stale=0")
    Response.AppendHeader("Cache-Control", "post-check=0")
    Response.AppendHeader("Cache-Control", "pre-check=0")
    Response.AppendHeader("Pragma", "no-cache")
    Response.AppendHeader("Keep-Alive", "timeout=3, max=993")
    Response.AppendHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT")

    However, are you sure that your site is secure enough? If a user logs out then clicks "BACK" does he get back into your app or is he prevented? If a user refreshes a page is he allowed to do multiple sql transactions where he should only be allowed to do one? If so you might want to check this out: http://aspalliance.com/687#Page2

    This javascript will prevent a user from going back to a particular page :
    <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
    <!--
    window.history.forward(1);
    //-->
    </SCRIPT>


    Here is how I implemented it in Asp.net:
    Embed the following scripts in the HTML in the login.aspx and logout.aspx webforms
    1) I put this javascript on the login page
    <script language="Javascript">
    <!--
    javascript:window.history.forward(1);
    //-->
    </script>

    2)I put this javascript on the logout page
    <script language="Javascript">
    <!--
    javascript:window.history.forward(1);
    window.location="login.aspx"//redirect to the login page immediately
    //-->
    </script


    When the user clicks the logout button/link then the logout.aspx page redirects to the login.aspx page and both these javascripts prevents the user from going back into the app without logging in.

    Javascript must be enabled in the client browser for this to work so you might want to test for that and display a message if it is not.

    You may also want to clear all session variables when the user logs out and run some form of validation on each page to test if these variables are set. This will prevent the user from typing in a URL directly in the browser and retreiving someone else's data.
    Last edited by ToxXxic; Aug 17, 2007 at 11:57 PM.
    Code King aka Code WizZzard: Motivated By The Challenge, Driven By The Will To Succeed.

    In The Land Of Programmers, The Code WizZzard Is KING. Sen on anything VB

  5. #5
    Join Date
    Jul 2006
    Posts
    276
    Rep Power
    0

    Default Respect toxic

    Respect to all you guys who tried to help. The code works fine! All i did was to place it on the load event and it works so far perfectly! Dont know if it will trigger some kind of error elsewhere but its a chance i have to take until then! Are there any other solutions?
    Last edited by norminator; Aug 17, 2007 at 11:31 AM.
    The greatest discovery of all men through lifetime is that a man can alter his life by altering his attitude!

  6. #6
    Join Date
    Feb 2005
    Posts
    85
    Rep Power
    0

    Default

    Quote Originally Posted by norminator View Post
    The code works fine! All i did was to place it on the load event and it works so far perfectly!

    Anytime. Glad To help
    Code King aka Code WizZzard: Motivated By The Challenge, Driven By The Will To Succeed.

    In The Land Of Programmers, The Code WizZzard Is KING. Sen on anything VB

  7. #7
    Join Date
    Feb 2005
    Posts
    85
    Rep Power
    0

    Default

    Additionally are you protected from SQL Injection? For example if a user types something like password' or '1'='1 in the password field and submitts it, will this cause him to bypass your login?

    Copy and paste all that is displayed in red above, in the password textbox and try to bypass your security. Any username should work with this
    Last edited by ToxXxic; Aug 27, 2007 at 02:40 PM.
    Code King aka Code WizZzard: Motivated By The Challenge, Driven By The Will To Succeed.

    In The Land Of Programmers, The Code WizZzard Is KING. Sen on anything VB

  8. #8
    Join Date
    Jul 2006
    Posts
    276
    Rep Power
    0

    Default nope

    Quote Originally Posted by ToxXxic View Post
    Additionally are you protected from SQL Injection? For example if a user types something like password' or '1'='1 in the password field and submitts it, will this cause him to bypass your login?

    Copy and paste all that is displayed in red above, in the password textbox and try to bypass your security. Any username should work with this
    It doesnt bypass my login page, what exactly does it do?
    The greatest discovery of all men through lifetime is that a man can alter his life by altering his attitude!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •