RedirectFromLoginPage - 无法找到资源错误

时间:2013-05-10 12:52:42

标签: c# asp.net

我正在c#

中设置登录
if (TextBox1.Text == System.Convert.ToString(row["Username"]) &&
        (TextBox2.Text == System.Convert.ToString(row["Password"])))
            System.Web.Security.FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false);

    else
        Label1.Text = "Invalid Username/Password"; //If incorrect show this label

用户输入正确的详细信息后,我会得到一个页面The resource cannot be found我的问题是我在哪里设置应该重定向到的页面?

到目前为止,我的web.config看起来像这样

<authentication mode="Forms">
 <forms>

 </forms>

我正在连接数据库以获取正确的详细信息,此部分仅用于重定向页面。

1 个答案:

答案 0 :(得分:4)

RedirectFromLoginPage方法重定向到returnUrl查询字符串参数中指定的页面,或者作为后备,重定向到web.config中指定的defaultUrl属性:

<authentication mode="Forms">
  <forms loginUrl="member_login.aspx"
    defaultUrl="index.aspx" />
</authentication>

有关详细信息,请参阅此处:

RedirectFromLogin:http://msdn.microsoft.com/en-us/library/ka5ffkce.aspx

DefaultUrl:http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.defaulturl.aspx