I am a new to ASP.Net. Please, explain me what I need to add.
I clicked this page before login to take user to login page by “FormsAuthentication.RedirectToLoginPage();”. But After Page_Load , it goes to “dsRequestList_Selecting”. I assumed it goes directly to Login page, but here some reason it goes to login page after dsRequestList_Selecting(). What do I need to do?
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
if (!HttpContext.Current.User.Identity.IsAuthenticated)
{
FormsAuthentication.RedirectToLoginPage();
}
}
else
{
if (!HttpContext.Current.User.Identity.IsAuthenticated)
{
FormsAuthentication.RedirectToLoginPage();
}
}
}
protected void dsRequestList_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
//Selecting
}
Don’t go this way.
Use Web.config (or, for MVC, the
[Authorize]attribute) to secure pages. You don’t need this kind of code and you don’t want the susceptibility to errors (in every page) that it brings.You only need
to secure all your pages in the same folder as this web.config. The loginform is automatically excepted.