943,617 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 475
  • ASP.NET RSS
Sep 29th, 2009
0

Forms Authentication

Expand Post »
WEB.CONFIG FIlE
ASP.NET Syntax (Toggle Plain Text)
  1. <?xml version="1.0"?>
  2. <configuration>
  3. <appSettings/>
  4. <connectionStrings/>
  5. <system.web>
  6. <authentication mode ="Forms">
  7. <forms loginUrl="FrmLogin.aspx" protection="All" >
  8. <credentials passwordFormat="Clear">
  9. <user name="sonia" password="citm123"/>
  10. <user name="soni" password="citm123" />
  11. <user name="muru" password="citm1234"/>
  12. </credentials>
  13. </forms>
  14. </authentication>
  15. <authorization>
  16. <allow users="sonia"/>
  17. <allow users ="soni"/>
  18. <deny users="muru"/>
  19. </authorization>
  20. <compilation debug="true"/>
  21. </system.web>
  22. </configuration>


FRMLOGIN.aspx
ASP.NET Syntax (Toggle Plain Text)
  1. protected void btnLogin_Click(object sender, EventArgs e)
  2. {
  3. if (FormsAuthentication .Authenticate(txtUserName .Text ,txtPassword .Text ))
  4. {
  5. FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, true);
  6.  
  7. Response.Redirect("FrmWelcome.aspx?username=" + txtUserName.Text );
  8. }
  9.  
  10. }

FRMWELCOME.aspx
ASP.NET Syntax (Toggle Plain Text)
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3.  
  4. lblUserName.Text = Request.QueryString["username"].ToString();
  5.  
  6.  
  7. }


Suppose i enter sonia in username & citm123 in password. I will be redirected to FrmWelcome. Suppose now the user copies the URL of FrmWelcome & open in other window,i want that the user is navigated to FrmLogin. How to do it.Using Cookies??? Can somebody help me out!
Similar Threads
Reputation Points: 0
Solved Threads: 8
Posting Whiz
sonia sardana is offline Offline
326 posts
since Mar 2008
Sep 30th, 2009
0

Re: Forms Authentication

You are only denying access to the user 'muru'. It means that users other than 'muru' can access the application anonymously.

If you want to prevent the users to access the FrmWelcom or other pages without login to the system, your web.config should be as below
ASP.NET Syntax (Toggle Plain Text)
  1. <authorization>
  2. <allow users="sonia"/>
  3. <allow users="soni"/>
  4. <deny users="muru"/>
  5. <deny users="?"/>
  6. </authorization>

The '?' in deny element prevents anonymous access to the resources.

Also the set the second argument in the statement FormsAuthentication.RedirectFromLoginPage to false.

ASP.NET Syntax (Toggle Plain Text)
  1. FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, false);
Setting true will create a durable cookie (one that is saved across browser sessions). Therefore you need to set it as false.
Last edited by Ramesh S; Sep 30th, 2009 at 2:17 am.
Reputation Points: 165
Solved Threads: 113
Posting Pro
Ramesh S is offline Offline
580 posts
since Jun 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Running apps in subfolders in Visual Studio with MS SQL
Next Thread in ASP.NET Forum Timeline: Hashtable data





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC