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

[C#]VS调试通常 但在IIS 验证无法跳转正确页面

2011-12-10 
[C#]VS调试正常 但在IIS 验证无法跳转正确页面这是个身份验证并且跳转到请求页面的web.config和logon.aspx

[C#]VS调试正常 但在IIS 验证无法跳转正确页面
这是个身份验证并且跳转到请求页面的web.config   和   logon.aspx.cs文件的内容

出现的问题如下:


---------------------请注意这段话-----------------------------------------
在VS2005下   用CTRL+F5   或者F5直接调试的话   没有任何异常   验证请求以及验证通过之
后的跳转   都正常
---------------------------------------


但是发布到IIS上就出问题了   请求页面的时候可以自动连接到Logon.aspx   但是输入正确的用户名和密码之后   页面只是原地刷新     不跳转到我请求的页面.

IIS设置的默认主页是Default.aspx   我请求的页面也是这个   IIS除了主目录和默认主页类型其他选项全都是默认的.

开始输入地址后   IE地址栏显示:
http://127.0.0.1:8010/logon.aspx?ReturnUrl=%2fDefault.aspx
之后无论输入正确还是错误的验证都变成:
http://127.0.0.1:8010/logon.aspx


//=====================web.config内容=======================

<configuration>
<appSettings/>
//-------------------------------------------
        <connectionStrings>
<addname= "DB_360ConnectionString "connectionString= "DataSource=*****;InitialCatalog=*****;PersistSecurityInfo=True;UserID=*****;Password=***** "providerName= "System.Data.SqlClient "/>
        </connectionStrings>
//-------------------------------------------
<system.web>
        <roleManager   enabled= "true "/>
        <compilation   debug= "true "/>
//--------------------------------------------
        <authentication   mode= "Forms ">
                <forms   name= ".ASPXFORMSDEMO "   loginUrl= "logon.aspx "   protection= "All "   path= "/ "   timeout= "30 "/>
        </authentication>
//----------------------------------------
        <authorization>
                <deny   users   = "? "   />
                <allow   users   =   "* "   />
        </authorization>
//----------------------------------------
<httpRuntime   useFullyQualifiedRedirectUrl= "true "/>
<mobileControls   cookielessDataDictionaryType= "System.Web.Mobile.CookielessData "/>
//-----------------------------------------


//===============logon.aspx.cs内容====================

public   partial   class   Logon   :   System.Web.UI.Page
{
        public   static   string   uid;

//-----------------------------------------------

        private   bool   ValidateUser(string   userName,   string   passWord)
        {
                SqlConnection   conn;
                SqlCommand   cmd;
                string   lookupPassword   =   null;
                if   ((null   ==   userName)   ||   (0   ==   userName.Length)   ||   (userName.Length   >   15))
                {
                        return   false;


                }
                if   ((null   ==   passWord)   ||   (0   ==   passWord.Length)   ||   (passWord.Length   >   25))
                {
                        return   false;
                }

                try
                {
                        conn   =   new   SqlConnection( "server=localhost;Integrated   Security=SSPI;database=***** ");
                        conn.Open();

                        cmd   =   new   SqlCommand( "Select   pwd   from   users   whereuname=@userName ",   conn);
                        cmd.Parameters.Add( "@userName ",   SqlDbType.VarChar,   25);
                        cmd.Parameters[ "@userName "].Value   =   userName;
                        string.
                        lookupPassword   =   (string)cmd.ExecuteScalar();

                        cmd.Dispose();
                        conn.Dispose();
                }
                catch   (Exception   ex)
                {

                }

                if   (null   ==   lookupPassword)
                {
                      return   false;
                }          
                HttpCookie   tmpCooki   =   new   HttpCookie( "nowid ");
                tmpCooki.Value   =   userName;
                Response.Cookies.Add(tmpCooki);
                return   (0   ==   string.Compare(lookupPassword,   passWord,   false));
        }
//----------------------按登陆按钮事件-------------------------

        protected   void   cmdLogin_ServerClick1(object   sender,   EventArgs   e)
        {
               
               
                if   (ValidateUser(txtUserName.Value,   txtUserPass.Value))
                        FormsAuthentication.RedirectFromLoginPage(txtUserName.Value,chkPersistCookie.Checked);


                else
                        Response.Redirect( "logon.aspx ",   true);
     
        }
}


请求帮助     无限感激

[解决办法]
Response.Redirect( "logon.aspx ", true);

把这个代码该吓 比如说跳到 baidu.com去 如果还是出现不管输入正确或错误都跳到baidu去的情况 那么肯定是你的用户名和密码的问题了

要么就是服务器的客户端事件丢失 在vs的命令行中输入 aspnet_regiis -i 重新注册下
[解决办法]
<authentication mode= "Forms ">
<forms name= ".ASPXFORMSDEMO " loginUrl= "logon.aspx " protection= "All " path= "/ " timeout= "30 "/>
</authentication>
这个地方应该有问题
[解决办法]
加上

<configuration>
<location path= "logon.aspx ">
<system.web>
<authorization>
<allow users= "? "/>
</authorization>
</system.web>
</location>
</configuration>


logon.aspx页面必须允许匿名访问

[解决办法]
把校验那块的
try{}catch{}
去掉在调试

个人经验:在设计时尽量不要用异常处理,程序早崩溃是件好事

热点排行