locked
how to redirect to a page in a different sub folder off the main project folder? RRS feed

  • Question

  • User-1410783915 posted

    After a user presses the save button, I save the data and then need to refresh the page. I am using Response.Redirect to redirect to the same page in order to refresh it, however I keep getting the error page "The resource cannot be found". Below are the many redirects I have tried and they all do not work.

    Response.Redirect(Request.RawUrl + "?Id=" + Session["SavedId"].ToString())
    Response.Redirect("dataInput.aspx" + "?Id=" + Session["SavedId"].ToString())
    Response.Redirect("..\dataInput.aspx" + "?Id=" + Session["SavedId"].ToString())
    Response.Redirect("MainPages\dataInput.aspx" + "?Id=" + Session["SavedId"].ToString())

    Response.Redirect("MainPages\dataInput.aspx" + "?Id=" + Session["SavedId"].ToString())
    Response.Redirect("\MainPages\dataInput.aspx" + "?Id=" + Session["SavedId"].ToString())

    The page I am redirecting to is in a folder named "MainPages". However the redirect keeps looking for the aspx page I am redirecting to in a different folder
    named "CommonPages". So even though I am explicitly trying to redirect to folder MainPages, the redirect is looking in folder CommonPages.
    So what am I doing wrong here?

    Both folder "MainPages" and "CommonPages" are subfolder off the main project named "MainProject".

    ClientSol  -----MainProject------| MainPages -----> dataInput.aspx
                                                       | CommonPages

    Wednesday, April 5, 2017 11:22 PM

Answers

  • User-1509636757 posted

    However the redirect keeps looking for the aspx page I am redirecting to in a different folder named "CommonPages"

    Since you are explicitly redirecting to MainPages, it is hard to understand how code can redirect to CommonPages. I suggest you look at the router logic, your existing code that may causing this issue. Response.Redirect(Request.RawUrl); is the perfect way to redirect to itself.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 6, 2017 4:03 AM
  • User-2057865890 posted

    Hi Gleeming,

    Use Response.Redirect with having second parameter as "false" to avoid execution of page and thus to avoid lose session token. You could use URL as follows. 

    Response.Redirect(Request.RawUrl +
                    "?Id=" + Session["SavedId"].ToString(), false);

    where the false parameter makes sure that the response is not immediately killed.

    For example

    Response.Redirect("Default.aspx", false) means current page execution is not terminated and code written after the Response.Redirect("Default.aspx", false) is executed and then after the page is redirected to the Default.aspx.

    HttpResponse.Redirect Method (String, Boolean)

    Best Regards,

    Chris

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 6, 2017 4:14 AM

All replies

  • User-1509636757 posted

    However the redirect keeps looking for the aspx page I am redirecting to in a different folder named "CommonPages"

    Since you are explicitly redirecting to MainPages, it is hard to understand how code can redirect to CommonPages. I suggest you look at the router logic, your existing code that may causing this issue. Response.Redirect(Request.RawUrl); is the perfect way to redirect to itself.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 6, 2017 4:03 AM
  • User-2057865890 posted

    Hi Gleeming,

    Use Response.Redirect with having second parameter as "false" to avoid execution of page and thus to avoid lose session token. You could use URL as follows. 

    Response.Redirect(Request.RawUrl +
                    "?Id=" + Session["SavedId"].ToString(), false);

    where the false parameter makes sure that the response is not immediately killed.

    For example

    Response.Redirect("Default.aspx", false) means current page execution is not terminated and code written after the Response.Redirect("Default.aspx", false) is executed and then after the page is redirected to the Default.aspx.

    HttpResponse.Redirect Method (String, Boolean)

    Best Regards,

    Chris

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 6, 2017 4:14 AM
  • User-1410783915 posted

    Unfortunately I have already tried Request.RawUrl but the redirect is still looking in the other folder instead of the one I am redirecting to?

    Thursday, April 6, 2017 11:49 AM