Click here to Skip to main content
16,017,852 members
Please Sign up or sign in to vote.
2.33/5 (5 votes)
See more:
Hi guys,

I want to prepared Login control, not use ASP.NET inbuilt Login view. I need your ideas to prepare this.

Idea 1: this method I know and work on fine, get username and password from user and fire select query in database, if database give record then user is authenticated and, user name store in session variable. If I try getting other page directly with URL then first I check the session variable. If it is not null then we load page, otherwise we redirect user to login page.

Now for this I need to check each and every page before loading and I think there some other way also but which I can’t get that.

Guys, please provide me your valuable suggestions not source code. Code I will manage.

Thanks in advance.
Posted
Comments
Wild-Programmer 7-Apr-11 6:54am    
"suggestions not source code" 5+ for that :D
angle57 8-Apr-11 2:29am    
Hi Amit Kumar Tiwari,
Thanks for this link, but this article suggest Java scripts, if user disable the java script this option not work, second there is some code we need to write more than one page also. So I will not use this option.
Please have you any other suggestion?
Or other masters have any good suggestion?
Sreekanth Mothukuru 13-Sep-14 8:35am    
All you need to do is create a Base class and inherit it in all your pages. Write your validation code once. That's it.

Here is an article just for you
http://msdn.microsoft.com/en-us/library/aa478962.aspx[^]


Hope that helps. Good luck.
 
Share this answer
 
ASP.NET authentication and authorization[^]

Authorization MSDN[^]
MSDN Forms Authentication[^]
One of the best ones is:-
Cookieless ASP.NET forms authentication[^]
These are few very good links for providing authorization to everypage.
If you are using MVC, you can take use of the Authorization Attribute making a custom one. That would surely work out.

Hope these helps you anyway.
Thanks.
 
Share this answer
 
First off I'd suggest using Membership or Identity as you'll get all this out of the box. But if this is for learning then add a global.asax file to the solution and use the BeginRequest event to check if the user has logged in

C#
<%@ Application Language="C#" %>

<script runat="server">
void Application_BeginRequest(object sender, EventArgs e)
{
   if (string.IsNullOrWhiteSpace(Session["Username"])
   { 
       Response.Redirect("/Login.aspx")
   }

}
</script>
 
Share this answer
 
Comments
Blutfaust 21-Mar-15 12:40pm    
Nice, but four years late.
F-ES Sitecore 21-Mar-15 13:43pm    
Good advice is worth waiting for
Use Master page concept in your application. once you write the code for checking session variable in master page then its easy to work
 
Share this answer
 
Comments
Nelek 15-Feb-14 7:55am    
Almost 3 years late :P
Hareesh's answer is correct. Use master page concept and derive every of those pages with it on which you want to check User validation.
Write Login/Session check code in Page_Init event of master page. Now it's a very basic concept that before loading a child page, master page Page_Init will call. So your problem is solved.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900