.NET Response.Redirect("~/ ... does not go to subdirectory

Discussion in 'Site Programming, Development and Design' started by knetclr, Jul 13, 2010.

  1. Hello,

    I have uploaded my .net application to a subdirectory on my domain and I have writen the .asp to redirect mydomain.com to mydomain.com/subdirectory. I can see that my redirection .asp file is working because it calls my default.aspx file located on my subdirectory. The problem I am having now is that on my application when I have any call to Response.Redirect("~/anyfile.aspx", true); my application is redirecting to mydomain root directory again. What do I have to do for my application to redirect correctly to my mydomain.com/subdirectory?
  2. Ray


    I don't quite understand what you are trying to say.

    You have a redirect script and it works correctly. The startup page is default.apsx so if someone types mydomain.com or mydomain.com/default.aspx you get redirected to mydomain.com/subdirectory. Is that correct?

    But if someone types mydomain.com/anyfile.aspx you do not get redirected. Is that correct?
  3. What I meant was that after creating the default.asp on my root directory correctly, every time my applicaton would execute the command Response.Redirect("~/... it would not redirect to my subdirectory but it would go back to my domain root directory. I found the solution to my problem. I needed to change my web.config on my root directory to have all the <rewrite> <rules> to redirect all requests to my domain to my subdirectory. So, the default.asp was not enough to make everything work properly. I hope this can help someone else.
  4. Ray


    You should also be able to create the rules using IIS 7 manager/URL Rewrite. It will set the rules in your web.config file, or if you want you can go directly to the web.config and still do the same function. The IIS 7 Module is just more user friendly because it is a GUI.

Share This Page