Forms auth problem

T

Tumurbaatar S.

My app Web.config contains:

<authentication mode="Forms">
<forms name="myauth" loginUrl="default.aspx" protection="All"
timeout="1" />
</authentication>

And default.aspx shows login/password form, checks posted values
and if login is allowed, stores these values in Session:

private void Page_Load(object sender, System.EventArgs e)
{
FormsAuthentication.SignOut();
if (IsPostBack)
{
....// code to validate login/password
FormsAuthentication.SetAuthCookie(LoginTxt.Text, false);
Session["UID"] = LoginTxt.Text;
Session["PSW"] = PassTxt.Text;
Response.Redirect("admin.aspx", true);
}
catch (Exception err)
{
ErrorLbl.Text = err.Message;
}
}
}

This works well when a client starts at the default page. But when
a not logged client loads other pages directly, IIS does not redirect
automatically to loginUrl and executes the selected page. And, of course,
referencing there Session collection for unknown items (UID/PSW), raises
exception.
What am I doing wrong?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top