There are a few ways to do this. For instance, after the user enters his credentials, save them in the Session object.
Then, in the Page_Load
of sensitive-informations.aspx make sure the Session object exists.
To better illustrate this:
In your login.aspx.cs page:
protected btnLoginClick(...)
{
// CHECK USERNAME and PASSWORD
if (UserIsAuthenticated)
{
Session["UserName"] = user;
}
}
Then in your sensitive-informations.aspx.cs
protected page_load(...)
{
// If UserName doesn't exist in Session, don't allow access to page
if (Session["UserName"] == null)
{
Response.Redirect("INVALID_USER.aspx");
}
}
Edit:
Based on OPs comments, if you want to know which page you came from, you can either use:
Page.PreviousPage like this:
protected void Page_Load(object sender, EventArgs e)
{
var x = this.Page.PreviousPage;
Or use Request.UrlReferrer like this:
protected void Page_Load(object sender, EventArgs e)
{
var x = Request.UrlReferrer;
In both cases make sure x
isn't null first...