asp.net 和 HTML 提交不同了,是做在 “登录” 那个按钮的事件里面的,自己写一个控件,引用 ASP.NET forums 里面的类来做登录吧。 namespace xwsy.v8.ctrls { using System; using System.Data; using System.Drawing; using System.Web; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Collections; using System.Collections.Specialized; using AspNetForums; using AspNetForums.Components; using AspNetForums.Enumerations; using System.ComponentModel; using System.Web.Security; /// <summary> /// userlogin 的摘要说明。 /// </summary> public class userlogin : System.Web.UI.UserControl { protected System.Web.UI.WebControls.TextBox username; protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1; protected System.Web.UI.WebControls.TextBox password; protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2; protected System.Web.UI.WebControls.CheckBox autoLogin; protected System.Web.UI.WebControls.Button loginButton; private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); }
你在登录那页还可以用htm的来..然后提交到login.aspx,
用Request["UserName"]
Request["Password"]
帐 号:
</td>
<td>
<input name="_ctl0:MainContent:_ctl0:_ctl0:username" type="text" maxlength="64" id="_ctl0_MainContent__ctl0__ctl0_username" size="11" />
</td>
</tr>
<tr>
<td align="right" class="txt3">
密 码:
</td>
<td>
<input name="_ctl0:MainContent:_ctl0:_ctl0:password" type="password" maxlength="64" id="_ctl0_MainContent__ctl0__ctl0_password" size="11" />
</td>我提交过去 一点反映都没有
可是它的代码就这么几句:<%@ Import Namespace="AspNetForums.Components" %>
<%@ Register TagPrefix="Forums" Namespace="AspNetForums.Controls" Assembly="AspNetForums.Controls" %>
<%@ Register TagPrefix="mp" Namespace="MetaBuilders.WebControls.MasterPages" Assembly="MetaBuilders.WebControls.MasterPages" %><mp:ContentContainer runat="server" id="MPContainer" MasterPageFile="~/Themes/MasterPage.ascx">
<mp:Content id="MainContent" runat="server">
<Forums:Login runat="server" />
</mp:Content>
</mp:ContentContainer>我真的不知道怎么看了
namespace xwsy.v8.ctrls
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls; using System.Collections;
using System.Collections.Specialized;
using AspNetForums;
using AspNetForums.Components;
using AspNetForums.Enumerations;
using System.ComponentModel;
using System.Web.Security; /// <summary>
/// userlogin 的摘要说明。
/// </summary>
public class userlogin : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.TextBox username;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.TextBox password;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected System.Web.UI.WebControls.CheckBox autoLogin;
protected System.Web.UI.WebControls.Button loginButton; private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.autoLogin.CheckedChanged += new System.EventHandler(this.autoLogin_CheckedChanged);
this.loginButton.Click += new System.EventHandler(this.loginButton_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void loginButton_Click(object sender, System.EventArgs e)
{
// 抄写 FORUMS 的登录验证代码 :)
User userToLogin = new User();
string redirectUrl = null; if (!Page.IsValid)
return; userToLogin.Username = username.Text;
userToLogin.Password = password.Text;
userToLogin.IPLastLogin = Globals.IPAddress;
LoginUserStatus loginStatus = Users.ValidUser(userToLogin); if( loginStatus == LoginUserStatus.Success )
{ // Are we allowing login?
// TODO -- this could be better optimized
if (!Globals.GetSiteSettings().AllowLogin)
{
bool allowed = false; int userid = Users.FindUserByUsername( userToLogin.Username ).UserID;
ArrayList roles = Roles.GetRoles(userid); foreach (Role role in roles)
{
if (role.Name == "Site Administrators" || role.Name == "Global Administrators")
{
allowed = true;
break;
}
} // Check the user is in the administrator role
if (!allowed)
{
throw new ForumException(ForumExceptionType.UserLoginDisabled);
}
} FormsAuthentication.SetAuthCookie(userToLogin.Username, autoLogin.Checked); // Check to ensure we aren't redirecting back to a Message prompt
//
if ((redirectUrl != null) && (redirectUrl.Length > 0))
redirectUrl = (Page.Request.QueryString["ReturnUrl"].IndexOf("MessageID") == 0 ? Page.Request.QueryString["ReturnUrl"] : Globals.GetSiteUrls().Home);
else
redirectUrl = ForumContext.Current.ReturnUrl; if (redirectUrl != null)
{
Page.Response.Redirect(redirectUrl, true);
}
else
{
Page.Response.Redirect("/v8/bbs/", true);
}
}
else if(loginStatus == LoginUserStatus.InvalidCredentials)
{ // Invalid Credentials
throw new ForumException(ForumExceptionType.UserInvalidCredentials, userToLogin.Username);
}
else if(loginStatus == LoginUserStatus.AccountPending)
{ // Account not approved yet
throw new ForumException(ForumExceptionType.UserAccountPending);
}
else if(loginStatus == LoginUserStatus.AccountBanned)
{ // Account banned
throw new ForumException(ForumExceptionType.UserAccountBanned, userToLogin.Username);
}
else if(loginStatus == LoginUserStatus.AccountDisapproved)
{ // Account disapproved
throw new ForumException(ForumExceptionType.UserAccountDisapproved, userToLogin.Username);
}
else if(loginStatus == LoginUserStatus.UnknownError)
{
// Unknown error because of miss-syncronization of internal data
throw new ForumException(ForumExceptionType.UserUnknownLoginError);
}
} private void autoLogin_CheckedChanged(object sender, System.EventArgs e)
{
}
}
}