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 li
nk( 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
protected void lnklogin_Click(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
Session.Abandon();
HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
cookie1.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie1);
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
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
>
}
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;
}