Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Response.Redirect() to a relative path

Tags:

asp.net

I'm working with ASP.net. My website is hosted within a subfolder test under the IIS root directory. So the url of default.aspx is http://localhost/test/Default.aspx. From default.aspx, I want to use Reponse.Redirect() with a relative path to redirect to another url within the same web site, http://localhost/test/whatever.

I tried

Response.Redirect("/whatever");

and

Response.Redirect("~/whatever");

Both of them redirect to http://localhost/whatever. Note that the Redirect method use http://localhost instead of http://localhost/test/ as the base url.

Any ideas?

Thanks.

like image 609
Shuo Avatar asked Jun 02 '10 18:06

Shuo


People also ask

What is the use of response redirect ()?

redirect() The redirect() method of the Response interface returns a Response resulting in a redirect to the specified URL.

What can I use instead of a response redirect?

For instance, instead of a "form" button that causes a postback and redirect, you could use a LinkButton that will behave like a hyperlink, allowing the browser to request the new page directly.

Does response redirect stop execution?

Response. Redirect("Default. aspx", true) means current page execution is terminated and page is redirected to the default.

What is redirect in ASP NET?

Redirect(String) Redirects a request to a new URL and specifies the new URL. Redirect(String, Boolean) Redirects a client to a new URL. Specifies the new URL and whether execution of the current page should terminate.


2 Answers

Try:

Response.Redirect("hello");

also

Response.Redirect("./hello");

Enjoy!

like image 102
Doug Avatar answered Nov 13 '22 17:11

Doug


Sorry if I'm over-simplifying or misunderstanding your question, but have you simply tried:

Response.Redirect("hello");
like image 3
0bj3ct.m3th0d Avatar answered Nov 13 '22 16:11

0bj3ct.m3th0d