a simple login form (.aspx file)
<p>
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Username:</asp:Label>
<asp:TextBox ID="UserName" runat="server" CssClass="textEntry"></asp:TextBox>
</p>
<p>
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
<asp:TextBox ID="Password" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
</p>
server side (aspx.cs file):
protected void Page_Load(object sender, EventArgs e)
{
if (FormsAuthentication.Authenticate(this.UserName.Text, this.Password.Text))
{
FormsAuthentication.RedirectFromLoginPage(this.UserName.Text, true);
}
}
add the following lines to web.config file:
<authentication mode="Forms">
<forms loginUrl="~/menu/Login.aspx" defaultUrl="~/menu/MenuMyApp.aspx" timeout="2880" cookieless="AutoDetect">
<credentials passwordFormat="Clear">
<user name="demo1" password="1"/>
<user name="demo2" password="2"/>
</credentials>
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
Your demo app is secure now.. Demo users can only login with the credentials specified.
For original article: http://www.codeproject.com/Articles/98950/ASP-NET-authentication-and-authorization#5 steps to enable authentication and authorization using Windows
Hiç yorum yok:
Yorum Gönder