Skip to main content

Posts

Showing posts from February, 2011

How to return same page after getting login?

Sometime we need to create user(if new) or login(Authenticate) to view particular page.
and after user is logged in, we need to return him to the same page.

And if new account is created user should logged-in and then need to return him to the same page.

to achieve this we can user Request.UrlReferrer property and can redirect back to original URL.

On Page_Load event

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["ReferrerUrl"] = Request.UrlReferrer.ToString();
            }
        }

Function to return to same page.

   private void ReturnBackExistingUser()
        {
            object referrer = ViewState["ReferrerUrl"];

            if (referrer != null)
            {
                Response.Redirect(referrer.ToString());
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }


If we have created new user then Add one line in functi…