C#Webforms-如何修复本地主机在登录后多次重定向的问题?

C#Webforms-如何修复本地主机在登录后多次重定向的问题?,c#,asp.net,webforms,form-authentication,C#,Asp.net,Webforms,Form Authentication,我想拒绝匿名用户并允许所有经过身份验证的用户访问。成功登录后,它应该重定向到默认页面。但是,它不断显示错误:重定向太多。它似乎一直重定向回登录页面。为什么以及如何修复它?下面是我的代码,我是否遗漏了导致问题的任何内容或做错了任何事情?提前谢谢 FormsAuthentication.SetAuthCookie(this.txtusername.Text, false); FormsAuthenticationTicket ticket = new FormsAuthenticationTick

我想拒绝匿名用户并允许所有经过身份验证的用户访问。成功登录后,它应该重定向到默认页面。但是,它不断显示错误:重定向太多。它似乎一直重定向回登录页面。为什么以及如何修复它?下面是我的代码,我是否遗漏了导致问题的任何内容或做错了任何事情?提前谢谢

FormsAuthentication.SetAuthCookie(this.txtusername.Text, false);

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                        1,                                      
                        this.txtusername.Text,              
                        DateTime.Now,                           
                        DateTime.Now.AddMinutes(30),            
                        false,                                  
                        Role                  
                        );
 HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName,
                FormsAuthentication.Encrypt(ticket));
                Response.Cookies.Add(cookie);    
                // the login is successful
                if (Request.QueryString["ReturnUrl"] == null)
                {                        
                    Response.Redirect("~/Default.aspx");                                              
                }                    


<authentication mode="Forms">
  <forms loginUrl="~/Account/Login.aspx" timeout="30"> </forms>
</authentication>
<authorization>
  <deny users="?" />
  <allow users="*" />
</authorization>
FormsAuthentication.SetAuthCookie(this.txtusername.Text,false);
FormsAuthenticationTicket=新FormsAuthenticationTicket(
1.
this.txtusername.Text,
日期时间,现在,
DateTime.Now.AddMinutes(30),
假,,
角色
);
HttpCookie cookie=新的HttpCookie(FormsAuthentication.FormScookeName,
FormsAuthentication.Encrypt(票证));
Response.Cookies.Add(cookie);
//登录成功
if(Request.QueryString[“ReturnUrl”]==null)
{                        
Response.Redirect(“~/Default.aspx”);
}                    

检查您的代码是否有带有
响应的无限循环。重定向
。如果找到,请在重定向前使用If条件,例如
If(!HttpContext.Current.Request.Path.EndsWith(“Login.aspx”,StringComparison.InvariantCultureIgnoreCase))响应。重定向(“Login.aspx”)
检查代码是否有无限循环,带有
响应。重定向
。如果找到,请在重定向前使用If条件,例如
If(!HttpContext.Current.Request.Path.EndsWith(“Login.aspx”,StringComparison.InvariantCultureIgnoreCase))响应。重定向(“Login.aspx”)