Wednesday 4 September 2013

form authentication

windows Authentication
 Formsauthentication
Press Me
Press Me
Press Me
i have two pages
login.aspx
default.aspx
add this code in web.config

<configuration>

    <system.web>
      <authentication mode="Forms">
        <forms  loginUrl="Login.aspx" defaultUrl="Default.aspx">
          <credentials passwordFormat="Clear">
            <user name="siv" password="jbs"/>
            <user name="sankar" password="jbs123"/>
          </credentials>
        </forms>
      </authentication>
        <compilation debug="false" targetFramework="4.0" />
    </system.web>

</configuration>
login page code is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (FormsAuthentication.Authenticate("siv", "jbs1"))
        {
            FormsAuthentication.RedirectFromLoginPage("siv", true);
        }
        else
            Response.Write("invalid user.");
    }
}

No comments:

Post a Comment