Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 形式认证重定向至登录页面不';行不通_Asp.net_Authentication_Redirect_Login - Fatal编程技术网

Asp.net 形式认证重定向至登录页面不';行不通

Asp.net 形式认证重定向至登录页面不';行不通,asp.net,authentication,redirect,login,Asp.net,Authentication,Redirect,Login,我有一个login.aspx。其中有一个重定向页面的代码 Server.Transfer(string.Format("~/admin/FillUserExtraInfo.aspx?UserName={0}",Server.UrlEncode(loginInitial.UserName))); 它确实起作用了,然后在FillUserExtraInfo.aspx中 protected void Page_Load(object sender, EventArgs e) {

我有一个login.aspx。其中有一个重定向页面的代码

Server.Transfer(string.Format("~/admin/FillUserExtraInfo.aspx?UserName={0}",Server.UrlEncode(loginInitial.UserName)));
它确实起作用了,然后在FillUserExtraInfo.aspx中

protected void Page_Load(object sender, EventArgs e)
    {
        // retrieve the username from the querystring
        userName = this.Request.QueryString["UserName"];
        string mode = UsefulFunctions.GetOperatingMode();
        if (mode == ConfigurationSettingValues.OperatingModes.Backup.ToString())
            FormsAuthentication.RedirectToLoginPage();
但是FormsAuthentication.RedirectToLoginPage()不起作用。程序继续向前执行,直到页面加载结束,然后返回登录

更新:在此期间,我找到了网址bacomes
http://localhost:53906/Login.aspx?ReturnUrl=%2fLogin.aspx%3fAction%3dLogout

最后。但我有一个错误:

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
My web.config:

<authentication mode="Forms">
        <forms loginUrl="Login.aspx" protection="All" timeout="30" requireSSL="false" slidingExpiration="true" defaultUrl="default.aspx" cookieless="UseDeviceProfile" enableCrossAppRedirects="false"/>
    </authentication>

我的问题是:

  • 为什么FormsAuthentication.RedirectToLoginPage()不起作用
  • 如何处理我遇到的错误
  • 多谢各位


    第二次更新:我在FormsAuthentication.RedirectToLoginPage()之后添加了Response.End(),然后它可以工作,但异常仍然存在。尝试使用Response.Redirect(“url”,false)而不是Server.Transfer()


    但我还需要传递变量“UserName”。我编辑了答案。请检查一下,我还没有测试。不知道为什么。无法重定向该页。它不起作用。你试着那样做有什么错误吗?手动放置任何有效用户名以检查响应。重定向(“~/admin/FillUserExtraInfo.aspx?username=“uname”,false);然后引发类型为“System.Threading.ThreadAbortException”的异常。无法计算表达式,因为代码已优化或调用堆栈顶部有本机框架。
    Response.Redirect("~/admin/FillUserExtraInfo.aspx?UserName=" + Server.UrlEncode(loginInitial.UserName) + "", false);