I play with authentication and authorization to prepare for some kind of task. I created two pages: Login.aspx and Default.aspx. In the configuration file, I set authentication for forms and refused to non-authenticated users:
<authentication mode="Forms">
<forms name="aaa" defaultUrl="~/Login.aspx" />
</authentication>
<authorization>
<deny users="?"/>
</authorization>
Then I wrote simple code to authenticate my user in Login.aspx:
protected void Page_Load(object sender, EventArgs e)
{
GenericIdentity identity = new GenericIdentity("aga", "bbb");
Context.User = new GenericPrincipal(identity, new String[] { "User" }); ;
Response.Redirect("~/Default.aspx");
}
When I run it, the redirect fails. Instead, Login.aspx is called again and again because the user is not authenticated (Context.User.Identity.IsAuthenticated is false on every download). What am I doing wrong?
source
share