C# .NET - How to keep a page is a session? - Asked By Daniel on 27-Oct-12 04:14 AM

Hi!I want to get back data on a page,after returning its url,means I was trying to send information to database but to send the info the system must check first if you are loggin, if not it will redirect you to an Authentication page then after loggin succeed it will take you back to that page you were working on with its value.This is the code I am using to get the returnurl,it is return the url with no data.

 if (HttpContext.Current.Session["UserId"] == null)
        {
            Response.Redirect("Login.aspx?ReturnUrl=ContactSupplier.aspx?");
            //Response.Redirect("Login.aspx");
        }
Rao B replied to Daniel on 27-Oct-12 06:34 AM
TRY THIS WAY

<asp:login id="ctlLogin" runat="server" onauthenticate="OnAuthenticate"
    onloggedin="OnLoggedIn" onloggingin="OnLoggingIn" destinationpageurl="~">
</asp:login>

protected void OnAuthenticate(object sender, AuthenticateEventArgs e)
{
    e.Authenticated = false;
    if (String.Compare(ctlLogin.UserName, "foo", true) == 0 &&
        String.Compare(ctlLogin.Password, "bar", false) == 0)
    {
        e.Authenticated = true;
    }
}		

protected void OnLoggedIn(object sender, EventArgs e)
{
    Response.Redirect("~");
}			
Daniel replied to Rao B on 27-Oct-12 09:37 AM
I do not understand this but let me be specific,I want to retain those value after the logged in of the user succeded,
http://localhost:11305/GemeyaSVN/ContactSupplier.aspx?sid=9&pid=225
http://localhost:11305/GemeyaSVN/ContactSupplier.aspx?sid=9&pid=225
These are differente page that I can get when requesting a specific page as you see
Try to explain with this code:
 if (HttpContext.Current.Session["UserId"] == null)
        {
           Page.Response.Redirect("Login.aspx?ReturnUrl=ContactSupplier.aspx);
     }
The problem after the user logged in this contactSupplier form returned with no data.