ASP.NET表单身份验证中的Returnurl =%2f问题 [英] Returnurl=%2f issue in ASP.NET forms authentication

查看:358
本文介绍了ASP.NET表单身份验证中的Returnurl =%2f问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

When I Loged into the web and clicked on Login, it was navigating to the LogIn page but it adds ''ReturnUrl=%2f'' to the URL. For example, authentication.aspx?ReturnUrl=%2fAXERP-UAT%2fsubsystem%2fmain_menu.aspx.After Login, it should point to this page subsystem/main_menu.aspx. Can anyone help me? Thanks a lot.



我尝试过的事情:

---------------------------------- web.config



What I have tried:

----------------------------------web.config

<appSettings>
    <add key="ConnectionString" value="AX-UAT;Integrated Security=false;Initial Catalog=SBG_AX_2020;User ID=sbax;Password=sbax;Connection TimeOut=99999" />
  </appSettings>

<authentication mode="Forms">
      <forms name="AXERP-UAT" loginUrl="authentication.aspx" protection="All" path="/" timeout="1500" />
    </authentication>
    <authorization>
      <deny users="*" />
    </authorization>



----------------------------编码C#



----------------------------CODING C#

protected void authenticate(object sender, EventArgs e)
    {
        if (txtUsername.Text == null | txtUsername.Text == string.Empty)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(''Error? Please enter email address'');", true);
            return;
        }

        if (txtPassword.Text == null | txtPassword.Text == string.Empty)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(''Error? Please enter password'');", true);
            return;
        }

        SqlConnection con_Check_UserData = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
        SqlCommand cmd_Check_UserData = new SqlCommand();
        try
        {
            cmd_Check_UserData.CommandText = "select * from VIEW_LOGIN where username = ''" + txtUsername.Text + "'' and password = ''" + txtPassword.Text + "''";
            cmd_Check_UserData.Connection = con_Check_UserData;
            con_Check_UserData.Open();
            System.Data.SqlClient.SqlDataReader rd_Check_UserData = cmd_Check_UserData.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
            if (rd_Check_UserData.HasRows)
            {
                while (rd_Check_UserData.Read())
                {
                    rd_Check_UserData.Read();
                    ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(''Login Successful'');", true);
                    Response.Redirect("subsystem/main_menu.aspx");

                    FormsAuthentication.RedirectFromLoginPage(txtUsername.Text.ToLower(), false);
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(''Invalid Username/ Password'');", true);
                return;
            }
        }
        catch (Exception ex)
        {
            con_Check_UserData.Close();
            Lbl_Message.Text = ex.Message;
            //Response.Redirect("main_menu.aspx");
            return;
        }
        finally
        {
            con_Check_UserData.Close();
        }

        con_Check_UserData.Dispose();
        cmd_Check_UserData.Dispose();
        con_Check_UserData = null;
        cmd_Check_UserData = null;

    }

推荐答案

这正是ReturnUrl 指向指向的内容.它只需要编码即可在querystring参数中使用.

但您还有更严重的问题要处理:

您的代码容易受到 SQL注入 [ ^ ]. 从不使用字符串连接来构建SQL查询. 总是使用参数化查询.

从不以纯文本形式存储密码:
简单地说明安全密码认证 [ Salted密码哈希-正确执行 [ ASP.NET身份 [ ^ ]


您想了解的有关SQL注入的所有信息(但不敢问)| Troy Hunt [ ^ ]
如何在没有技术术语的情况下解释SQL注入? |信息安全堆栈交换 [查询参数化备忘单| OWASP [ ^ ]
That''s exactly what the ReturnUrl is pointing to. It just has to be encoded to be used in a querystring parameter.

But you have more serious issues to deal with:

Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

NEVER store passwords in plain text:
Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

And why are you re-inventing the wheel? ASP.NET has several perfectly good authentication systems built-in - for example, ASP.NET Identity[^]


Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]


cmd_Check_UserData.CommandText = "select * from VIEW_LOGIN where username = '" + txtUsername.Text + "' and password = '" + txtPassword.Text + "'";


不是您的问题的解决方案,而是您遇到的另一个问题.
切勿通过串联字符串来构建SQL查询.迟早,您将使用用户输入来执行此操作,这将打开一个名为"SQL注入"的漏洞的大门,这对您的数据库很危险,并且容易出错.
名称中的单引号会导致程序崩溃.如果用户输入的名称如"Brian O" Conner"可能会使您的应用程序崩溃,则这是一个SQL注入漏洞,而崩溃是最少的问题,这是恶意的用户输入,并且使用所有凭据将其提升为SQL命令.
SQL注入-Wikipedia [ ^ ]
SQL注入 [ ^ ]
SQL注入攻击示例 [ PHP:SQL注入-手册 [ SQL注入预防作弊表-OWASP [


Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O''Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]


这篇关于ASP.NET表单身份验证中的Returnurl =%2f问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆