ZengCode.Com (The Thai Php Framework)  


Home   Download   Manual   About us    

Facebook   


MAIN MENU
News
Php Tips
Spring+Strut+Hibernate
Android Programming
Design Pattern By PHP
Ubuntu
Linux Quick Tips
C# Design Pattern
C# using Linq น่าใช้จริงๆ
C# Tips & Technique
Java & JavaScript Tips
Database & SQL
ZengCode Framework Guide
Zeng Code Code
Programming
IPhone (Tips and Trick)

Download เอกสารที่น่าสนใจ

     Authentication and Authorization in ASP.NET สไตล์ เซ็งโครต  (2009-11-03)

อันนี้ Authen mode Form นะครับ ใช้ Cookie

ผม optimize code ให้เข้าใจง่ายที่สุดแล้วครับ

 

======Login.aspx======

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
    <title>Login</title>
</head>
<body>
    <p class=title>Login</p>
    <span id="status" class="text" runat="Server"/>
    <form id="Form1" runat="server">
    Username: <asp:textbox id=username cssclass="text" runat="Server"/><br />
    Password: <asp:textbox id=password textmode=Password cssclass="text" runat="Server"/><br />
    <asp:button id=login_button onclick="Login_Click" text="  Login  " cssclass="button" runat="Server"/>
    </form>
</body>
</html>

 

========Login.aspx.cs===========

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Login_Click(object sender, EventArgs e)
    {
        if ( (username.Text == "chiwa") && (password.Text=="chiwa"))
            FormsAuthentication.RedirectFromLoginPage(username.Text, true);
        else
            status.InnerHtml += "Invalid Login";
    }
}

====Web.config======

<system.web>
    <authentication mode="Forms">
      <forms name="login" loginUrl="Login.aspx" protection="All" timeout="30" />
    </authentication>   
    <authorization>
      <deny users="?"/>
    </authorization>
</system.web>

 

อ่ะ กว่าผมจะทำความเข้าใจได้เล่นงง เหมือนกัน หรือว่าผมไม่ค่อยฉลาดก็มะรู้ งง


Comment
Name
Comment
Security CodeCAPTCHA Image

web hit counter

This page took 0.053175 seconds to load.