1、创建一个网站;
2、添加母板页MasterPage.master;
3、WebConfig文件添加如下配置:
<authentication mode="Forms"/> <authorization> <deny users="?"/> <allow users="*"/> </authorization>
4、MaterPage.master.cs代码
using System; using System.Web.UI.WebControls; using System.Web.Security; public partial class MasterPage : System.Web.UI.MasterPage { protected void Page_Load(object sender, EventArgs e) { // Popup dialog won't fire if user is already in. if (Request.IsAuthenticated) { LoginStatus1_ModalPopupExtender.Enabled = false; } else { LoginStatus1_ModalPopupExtender.Enabled = true; } } // When Login button clicked, authenticate user's crendential. protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { // You can add authentication logic here. e.Authenticated = ((Login1.UserName == "test") && (Login1.Password == "test")) ? true : false; // If login failed, continue showing the popup dialog and failure text. if (!e.Authenticated) { LoginStatus1_ModalPopupExtender.Show(); } } // When Cancel button clicked, hide the popup dialog. protected void btnCancel_Click(object sender, EventArgs e) { LoginStatus1_ModalPopupExtender.Hide(); } }
网站文件夹结构如下图:
文章链接:http://aspalliance.com/1882_How_to_Create_an__ASPNET_Modal_Popup_Login.all