Skip to main content

Posts

Showing posts from January, 2011

ASP.NET custom forms authentication - Part I

Forms authentication is generally used in internet facing applications. ASP.NET provides easy to use Membership Providers, Role providers etc. But some times we do need to right custom authentication code. That is what we are going to discuss today. Let us start with points to be considered:   Note : I am going to use cookie for state management. We need cookie for forms authentication. We need cookie for session management. We need to clear and abandon the session on logout.  We need to clear authentication ticket too. Web.config Here we have set the name for the authentication cookie. We have set the loginUrl - URL of the login page. We have set a defaultUrl - URL of the page where the user will be re-directed after login. for other attributes please visit this MSDN page. Authentication On (say) login button click write this code     protected void btnLogin_Click(object sender, EventArgs e)     {            if( Valid(userid,password) )          {       

ASP.NET formsauthentication - Images not displaying

Few days back I was working on an ASP.NET website. The website uses custom formsauthentication. I had the login page under the root directory and other pages and images etc in separate folders. So the structure was something like this:- Folder_Application Root       Folder_Pages       Folder_MasterPages       Folder_Images       Folder_Scripts       Folder_Controls File_Login.aspx                         //Files File_Web.config Problem statement:-  After publishing the website on the server I was not able to see the Images which were present on the login page.  Solution One:- I realized that I am using formsauthentication so I must allow anonymous access to the Images folder in order for the images to show up on login page. So I did that.    I was assuming that everything will be cool now. But it was not. As usual :) for we developers :). But surprisingly things were working fine on ASP.NET internal server. This shows there is something wrong wi