error handling in c#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lee Falin

    #1

    error handling in c#

    [color=blue]
    >-----Original Message-----
    >hello,
    >
    >i am trying to write aspx login system and the login[/color]
    process requires a[color=blue]
    >validity check of username and password.
    >
    >i have a c# class which calls the database and checks if[/color]
    the username and[color=blue]
    >password is valid, but if an incorrect username or[/color]
    password is entered i[color=blue]
    >want to raise an error to the aspx so i can display the[/color]
    error message. (i[color=blue]
    >hope this is the best way!).
    >
    >my code that raises the error is the username/password is[/color]
    invalid is:[color=blue]
    >
    >throw new Exception("The username/password is invalid.");
    >
    >
    >my problem is that when i run/debug my code this line[/color]
    makes the aspx stop[color=blue]
    >running and the error is displayed as a system error on[/color]
    the aspx page. how[color=blue]
    >can i pass the error message back to my aspx page so i[/color]
    can display it?[color=blue]
    >
    >thanks
    >
    >
    >[/color]
    ..[color=blue]
    >[/color]

    As Rob said this is a very expensive approach to user
    valdiation. A less expensive approach would be to use a
    stored procedure on the server that you pass a user name
    and password to. It then returns a value (maybe just a
    boolean) indicating if the login failed or not.

    So you could use something like the following:

    private bool UserLogin(strin g strUserName, string
    strPassword)
    {
    //Code to execute stored proc and return boolean
    }

    //////////////////

    //Check user login
    if(UserLogin("T om","Secret") )
    {

    //Good login
    }
    else
    {
    //login failed

    }

    Hope this helps,

    Lee
Working...