哪位好心人给我一份简单的会员登陆代码要C#和sqlserver2005结合的
急!!!!!
这是我写的……
login.aspx.csusing System;
using System.Data;
using System.Configuration;
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;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page 
{
    string constr;
    SqlConnection con;
    protected void Page_Load(object sender, EventArgs e)
    {
        constr = ConfigurationManager.AppSettings["connectionString"];
        con = new SqlConnection(constr);
    }
    protected void Button1_ServerClick(object sender, EventArgs e)
    {
        string sql = "select * from member_information where username='" + name.Value + "' and password='" + pw.Value + "'";
        SqlCommand cmd = new SqlCommand(sql, con);
        con.Open();
        SqlDataReader dr=cmd.ExecuteReader();
        if(dr.Read ())
        {
        FormsAuthentication .RedirectFromLoginPage (name.Value ,false);
        Label2.Text = "欢迎浏览!";
        }
        else 
            Label2.Text ="用户名或密码错误!";
    }
   
}web.config配置文件
<?xml version="1.0"?>
<!-- 
    注意: 除了手动编辑此文件以外,您还可以使用 
    Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
     “网站”->“Asp.Net 配置”选项。
    设置和注释的完整列表在 
    machine.config.comments 中,该文件通常位于 
    \Windows\Microsoft.Net\Framework\v2.x\Config 中
-->
<configuration>
<appSettings>
<add key="connectionString" value="Data source=./SQLEXPRESS;Initial Catalog=member_information;Integrated Security=True"/>
</appSettings>
<system.web>
<authentication mode="Windows">
<forms name="_Auth_12_5" loginUrl="index.aspx" defaultUrl="index.aspx"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
<!--sessionState元素中设置会话状态。允许使用cookie,session有效期为20分钟-->
<sessionState mode="InProc" stateConnectionString="tcpip=20100120-1252:8080" sqlConnectionString="data source=20100120-1252;Trusted_Connection=yes" cookieless="false" timeout="20"/>
<globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
<compilation defaultLanguage="c#" debug="true"/>
</system.web>
<connectionStrings>
<add name="finalworkConnectionString" connectionString="Data Source=20100120-1252;Initial Catalog=finalwork;Persist Security Info=True;User ID=sa;Password=zhaixiaoyu" providerName="System.Data.SqlClient"/>
<add name="finalworkConnectionString2" connectionString="Data Source=20100120-1252;Initial Catalog=finalwork;Persist Security Info=True;User ID=sa;Password=zhaixiaoyu" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<!-- 
            设置 compilation debug="true" 将调试符号插入
            已编译的页面中。但由于这会 
            影响性能,因此只在开发过程中将此值 
            设置为 true。
        -->
<!--compilation元素设置变异情况,启用ASPX调试,应用程序的编程语言为C#-->

<!--
            通过 <authentication> 节可以配置 ASP.NET 使用的 
            安全身份验证模式,
            以标识传入的用户。 
        -->
<!--
            如果在执行请求的过程中出现未处理的错误,
            则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
            开发人员通过该节可以配置
            要显示的 html 错误页
            以代替错误堆栈跟踪。        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
</system.web>
</configuration>
问题原因:不报错 输入用户名和密码点击后页面没反应,密码等输错也没反应!

解决方案 »

  1.   

    跟踪一下就OK了  lx接分
      

  2.   

    FormsAuthentication .RedirectFromLoginPage (name.Value ,false); 这句注销
      

  3.   

    注销后还是没有反应 ~~~~(>_<)~~~~ 
      

  4.   

    1.
    将<authentication mode="Windows">
    改成
    <authentication mode="Forms">2.前台用户输入表单中, 用户名控件ID要设为"UsernameText"
                        密码输入控件ID要设为"PasswordText"
    如果要进一步使用成员资格,第2步很重要3.在后台验证代码中:
    protected void Button1_ServerClick(object sender, EventArgs e) 
    {
    if (FormsAuthentication.Authenticate(UsernameText.Text,PasswordText.Text))
    {
    FormsAuthentication.RedirectFromLoginPage(UsernameText.Text,false); 
            Label2.Text = "欢迎浏览!"; 
    }
     else { Label2.Text ="用户名或密码错误!"; }
    }如果你是自建的用户信息表,那就需要按你的办法写查询数据代码.不过你的SQL语句是拼接的,很容易被人恶意注入
      

  5.   

    1.如果改成form我的页面css样式不可以显示
    2.我添加服务器控件后会报错,不允许我用服务器控件。
    3.我把html控件加上runat="sever"后,在后台编译时,应该是控件名.Text,但我的没有Text这个属性 只有value。(我的页面是用Dreamweaver做好后贴过来的)
      

  6.   

    总是说我发打开登陆所请求的数据库 登陆失败 
    con.open();错!
    请问怎么改~
    我哪里有问题呢?
      

  7.   

    <!--
        注意: 除了手动编辑此文件以外,您还可以使用
        Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
        “网站”->“Asp.Net 配置”选项。
        设置和注释的完整列表在
        machine.config.comments 中,该文件通常位于
        \Windows\Microsoft.Net\Framework\v2.x\Config 中
    -->
    <configuration>
    <appSettings>
    <add key="connectionString" value="Data source=./SQLEXPRESS;Initial Catalog=member_information;Integrated Security=True"/>
    </appSettings>
    <system.web> 
    数据库链接出错应该是:<add key="ConnectionString" value="server=.\SQLEXPRESS;database=你的数据库名称;uid=sa;pwd=你的密码"/>给分吧!呵呵!