Click here to Skip to main content
14,732,982 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am struct with redirect thing in my web application with c#.

when i enter the login page and complete all the fuctionalities and then redirect to next page the url /Login?ReturnUrl=%2f is been shown.

So I googled the issue and added these lines in web.config
  <add key="autoFormsAuthentication" value="false" />
  <add key="enableSimpleMembership" value="false"/>

  <authentication mode="Forms">
    <forms loginUrl="~/Account/Login.aspx" timeout="43280" />

But still the same url is been displayed when i do Response.Redirect("SelectApp.aspx"); where in SelectApp.aspx is a webform placed under Account folder where in the Login.aspx is also placed.
protected void LoginButton_Click(object sender, EventArgs e)
    SqlCommand cmd = new SqlCommand("select * from UserMaster where USER_NAME =@username and USER_PWD1=@password", con);

    //string enPwd = Encode(Password.Text);
    cmd.Parameters.AddWithValue("@username", UserName.Text);
    cmd.Parameters.AddWithValue("@password", Password.Text);

    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();


    if (dt.Rows.Count > 0)
      ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>");

I have added the Code above. But i am not getting any solution for my problem.
Updated 30-Sep-15 19:39pm
Suvabrata Roy 1-Oct-15 1:35am
What exactly your problem? I am unable to understand it from your post
Naveen.Sanagasetti 1-Oct-15 2:04am
I guess, if you include "~" symbol your problem solved.

F-ES Sitecore 1-Oct-15 5:24am
If anonymous users can't access SelectApp.aspx then any attempt to access it will result in a redirection to your login page, that includes redirects from your own code. There is nothing in your login button click event that is authenticating the user so redirecting to SelectApp will just kick them back to the login page.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900