Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i have tw0 pages

default.aspx and login.aspx.

on login page i enter username and password.. the problem is that when i directly debug the login.aspx page . error come http 404 not found

but when i debug ( run) default.aspx page and click on the login link( code for login link is below). which redirects the page to the login.aspx and after that when i enter username and password it works fine.. why login.aspx page is not working directly

i have login link on default.aspx page

i put the code in login link which is on default.aspx page and it redirect the page to login.aspx
C#
protected void lnklogin_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
        Session.Abandon();

        // clear authentication cookie
        HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
        cookie1.Expires = DateTime.Now.AddYears(-1);
        Response.Cookies.Add(cookie1);

        // clear session cookie (not necessary for your current problem but i would recommend you do it anyway)
        HttpCookie cookie2 = new HttpCookie("ASP.NET_SessionId", "");
        cookie2.Expires = DateTime.Now.AddYears(-1);
        Response.Cookies.Add(cookie2);

        FormsAuthentication.RedirectToLoginPage();
        
    }



it will redirect me to the login page...


on login page i have a code


C#
 ecprops _user = new ecprops();
         dbcon dbo = new dbcon();
        _user = dbo.CheckUser(txtUserid.Text);
        if (_user != null)
        {
            if (_user.Password == txtPassword.Text)
            {
                FormsAuthenticationTicket Authticket = new FormsAuthenticationTicket(
                                                        1,
                                                        txtUserid.Text,
                                                        DateTime.Now,
                                                        DateTime.Now.AddMinutes(30),
                                                        chkRemeberMe.Checked,
                                                        _user.RoleName,
                                                        FormsAuthentication.FormsCookiePath);

                string hash = FormsAuthentication.Encrypt(Authticket);

                HttpCookie Authcookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);

                if (Authticket.IsPersistent) Authcookie.Expires = Authticket.Expiration;

                Response.Cookies.Add(Authcookie);

                string returnUrl = Request.QueryString["ReturnUrl"];
                if (returnUrl == null) returnUrl = "/";

                Response.Redirect(returnUrl);

                
            }
            else
            {
                lblMessage.Text = "Password does'nt match.";
            }
        }
        else
        {
            lblMessage.Text = "User not exists.";


i put the fallwoing in webconfig

<pre lang="HTML"><<pre>authentication mode="Forms">
        <forms loginUrl="login.aspx"
          name=".ASPXAUTH"
          protection="All"
               timeout="90" slidingExpiration="true"></forms>
      </authentication>
      <authorization>
        <allow users="*"/>
      </authorization
>
}



C#






public ecprops CheckUser(string UserName)
        {
            MAconn = new SqlConnection(connectionString);
            const string SP_CHECKUSER = "CheckUser";
            MAconn.Open();
            MAcmd = new SqlCommand(SP_CHECKUSER, MAconn);
            MAcmd.CommandType = CommandType.StoredProcedure;
            MAcmd.Parameters.Add("@UserName", DbType.String).Value = UserName;
            dr = MAcmd.ExecuteReader();
           ecprops _user = null;
            while (dr.Read())
            {
                _user = new ecprops();
                _user.Password = dr["Password"].ToString();
                _user.RoleName = dr["RoleName"].ToString();
            }
            return _user;
        }
Posted
Updated 17-Sep-11 6:43am
v4
Comments
rkthiyagarajan 17-Sep-11 0:05am    
Check your web.config page.. Whether you use form authentication or not?
codegeekalpha 17-Sep-11 4:26am    
i put the code of web config in the question pls check it..

Hi,

Upto my knowledge you've to wrote something error in login.aspx pageload method

or some code error in login button event.I'm not familier with form authentication

that's y I'm unable to check your code now,but my sujestion is just check your pageload method code in login.aspx page.
 
Share this answer
 
Comments
codegeekalpha 17-Sep-11 4:36am    
if i debut directly the login page.. if i put wrong password.. lbl shows me wrong password but if the password is correcct it says server error
rkthiyagarajan 17-Sep-11 4:54am    
Remove authorization tag and run it..
Muralikrishna8811 17-Sep-11 4:40am    
you know , is your authentication code is correct?
codegeekalpha 17-Sep-11 5:18am    
yes it is correct..
Muralikrishna8811 17-Sep-11 5:20am    
If don't can you specify your project flow for these first steps.

I can write code for login process.
perhaps "~/Login.aspx". By only stating login.aspx and you don't where youa re in your folderstructure at IIS it is very possible he cannot find the page.
 
Share this answer
 

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