custom user login with ASP.NET using SQL and C# -
i've been working on asp.net application , i've managed create login , register webpage linked sql database using c# server-side code.
problem:
couldn't find method keep user logged in while opening different pages, best method 100% customizable, preferably tot using "logincontrols".
time!
the user tied session
. pages have property available. it's httpsessionstate
object, , can house logged in user information. now, can encapsulate lot of work building user
class has static
accessors pull data out of session. example:
public static class user { public static bool isauthenticated { { var session = httpcontext.current.session; return !string.isnullorempty(session["loggedinuser"]); } } public static string username { { return session["loggedinuser"]; } } public static bool login(string username, string password) { // login (i.e. verify user name , password // build kind of session indicator httpcontext.current.session["loggedinuser"] = username; return true; } public static void logout() { if (!isauthenticated) { return; } httpcontext.current.session.abandon(); } }
and pages can stuff this:
user.login(txtusername.text, txtpassword.text);
Comments
Post a Comment