首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#中怎么做到登录失败后跳转到异常提示界面,而登陆成功后可以进入相应用户名的界面

2012-01-03 
C#中如何做到登录失败后跳转到错误提示界面,而登陆成功后可以进入相应用户名的界面%@PageLanguage C#

C#中如何做到登录失败后跳转到错误提示界面,而登陆成功后可以进入相应用户名的界面
<%@   Page   Language= "C# "   ContentType= "text/html "   ResponseEncoding= "gb2312 "   %>
<%@import   namespace= "System.Web.Security "%>
<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN "   "http://www.w3.org/TR/html4/loose.dtd ">
<html>
<script   language= "C# "   runat=server>
void   login(object   serder,EventArgs   e)
{
if(FormsAuthentication.Authenticate(txtuserid.Text,txtuserpsw.Text))
      FormsAuthentication.RedirectFromLoginPage(txtuserid.Text,true);
else
      Response.Redirect( "inputerror.aspx ");
}
</script>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
<title> 无标题文档 </title>
<script   language= "JavaScript "   type= "text/JavaScript ">
<!--


function   MM_reloadPage(init)   {     //reloads   the   window   if   Nav4   resized
    if   (init==true)   with   (navigator)   {if   ((appName== "Netscape ")&&(parseInt(appVersion)==4))   {
        document.MM_pgW=innerWidth;   document.MM_pgH=innerHeight;   onresize=MM_reloadPage;   }}
    else   if   (innerWidth!=document.MM_pgW   ||   innerHeight!=document.MM_pgH)   location.reload();
}
MM_reloadPage(true);

function   MM_preloadImages()   {   //v3.0
    var   d=document;   if(d.images){   if(!d.MM_p)   d.MM_p=new   Array();
        var   i,j=d.MM_p.length,a=MM_preloadImages.arguments;   for(i=0;   i <a.length;   i++)
        if   (a[i].indexOf( "# ")!=0){   d.MM_p[j]=new   Image;   d.MM_p[j++].src=a[i];}}
}
//-->
</script>
<style   type= "text/css ">
<!--
.style2   {
font-family:   "宋体-方正超大字符集 ";
font-size:   18px;
font-weight:   bold;
}
-->
</style> </head>
<body>
<div   id= "Layer1 "   style= "position:absolute;   width:567px;   height:426px;   z-index:1;   left:   140px;   top:   26px; ">
    <div   align= "center ">
        <p> <img   src= "&#30331;&#38470;&#30028;&#38754;.jpg "   width= "600 "   height= "400 "> </p>
        <div   id= "Layer2 "   style= "position:absolute;   width:455px;   height:138px;   z-index:2;   left:   143px;   top:   248px; ">
            <div   align= "left ">
                <form   action= " "   method= "post "   name= "form1 "   class= "style2 "   runat= "server ">
                    用户名
                    <asp:TextBox   ID= "txtuserid "   TextMode= "SingleLine "   runat= "server "   />                    


密码
<asp:TextBox   ID= "txtuserpsw "   TextMode= "Password "   runat= "server "   />
<asp:button   id= "butlogin "   onclick= "login "   text= "登陆 "   runat= "server "/>
 
                </form>
                <form   name= "form2 "   method= "post "   action= " ">
                    <div   align= "center "   class= "style2 "> 部门  
                        <input   type= "radio "   name= "radiobutton "   value= "radiobutton ">
                    老师  
                    <input   type= "radio "   name= "radiobutton "   value= "radiobutton ">
                    学生  
                      <input   name= "radiobutton "   type= "radio "   value= "radiobutton "   checked>
                    访客                    
                    <input   type= "radio "   name= "radiobutton "   value= "radiobutton ">
                    </div>
                </form>
            <strong>   </strong> </div>
        </div>
        <p> &nbsp; </p>
    </div>
</div>
</body>
</html>


我用了这个语句Response.Redirect( "inputerror.aspx ");   却实现不料这个功
能!在web.confirm表单中用户名和密码栏中也不允选有个相应的网址!各位大侠帮忙看看!先谢了!


[解决办法]
假设我用2个textBox分别输入用户名和密码
if(this.txt_userID.text!= " "){
if(this.txt_pass.text!= " "){Response.Redirect( "inputerror.aspx "); }
else{Response.Write( " <script> alert( "密码错误! "); </script> ");}
}
else {Response.Write( " <script> alert( "用户名错误! "); </script> ");
}

如果你建了数据库的话 你可以判断出密码是否和从数据库中取出来的一样不是的话报密码错误

[解决办法]
http://www.cnblogs.com/antony1029/archive/2006/10/21/536078.html

热点排行