标题:web.config 验证登陆
取消只看楼主
q314045513
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-5-9
 问题点数:0 回复次数:1 
web.config 验证登陆
web.config中:
<authentication mode="Forms">
      <forms loginUrl="login.aspx" timeout="2880" name="xx"  />
    </authentication>
    <authorization>
      <deny users="?"/>      添加此节后login.aspx页面 css格式全部清除,提交事件不响应......
    </authorization>

login.aspx 页面
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="project.login" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.

<html xmlns="http://www.
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用户登录</title>
<link href="images/login.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="javascript/jquery.min.js"></script>
<script type="text/javascript">
(function($){ $(document).ready(function(){
   
         $('.captcha').focus(function () {
            $('.yzm-box').show();
        });

        $('.captcha').focusout(function () {
            $('.yzm-box').hide();
        });
     })(jQuery);
</script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
           <div id="message-box"> 用户名或密码错误! </div>
        <div id="wrap">
   
              <div id="header"> </div>
              <div id="content-wrap">
                <div class="space"> </div>
         <div class="content">
        <div class="field"><label>账 户:</label>
                  <input class="username" name=""  type="text" id="username" runat="server"/></div>
        <div class="field"><label>密 码:</label>
                  <input class="password" name=""  type="password"  id="password" runat="server"/><br /></div>
        <div class="field"><label>验证码:</label>
                  <input class="captcha" maxlength="6" name=""  type="text" runat="server"  /><br />
        <div class="yzm-box"> </div>
        </div>
        <div class="btn">
              <%--  <input name="" type="submit" class="login-btn" value=""  />--%>
                <asp:Button ID="Button1" runat="server" Text=" " CssClass="login-btn"
                  onclick="Button1_Click"  />
        </div>
      </div>
    </div>
    <div id="footer"> </div>
</div>
        </div>
    </form>
</body>
</html>
login.aspx cs :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

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

        protected void Button1_Click(object sender, EventArgs e)
        {
            bool flag=checklogin(username.Value.Trim(), password.Value.Trim());
            if (flag==true)
            {
                Session["uname"]=username.Value.Trim();
                Response.Redirect("default.aspx");
            }
            else
            {
               
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), null, "<script>alert('用户名或密码错误!')</script>", false);
            }
        }


//验证用户名和密码
        public static bool checklogin(string uname, string pwd)
        {
            int rs = 0;
            using (SqlConnection con=new SqlConnection(ConfigurationManager.ConnectionStrings["tangzheng"].ConnectionString))
            {
                string sql = "select count(*)from users where username=@username and userpwd=@userpwd ";
                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Parameters.Add("@username", SqlDbType.VarChar).Value = uname;
                cmd.Parameters.Add("@userpwd", SqlDbType.VarChar).Value = pwd;
                con.Open();
                rs = Convert.ToInt32(cmd.ExecuteScalar());
                con.Close();
                if (rs>0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }


    }
}





正常情况:
[attach]70785[/attach]



[ 本帖最后由 q314045513 于 2013-5-9 17:39 编辑 ]
搜索更多相关主题的帖子: 验证 PUBLIC html 
2013-05-09 17:31
q314045513
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-5-9
得分:0 
添加 验证后 <deny users="?"/>
2013-05-09 17:39



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-406639-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.216889 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved