0

I'm facing with an odd situation and I think IIS is the cause, however since I'm not an expert in it so it is a guessing at this point. I asked our network admin and he did not agree.

In part of my C# code I'm redirecting the user to a new URL:

string currentURL = HttpContext.Current.Request.Url.Host;

string url = string.Format("http://" + currentURL + "/AppDir/Page1.aspx?Item={0}&From={1}",
                           employeeNo, "Search");

Response.Redirect(url, true);

But, out of nowhere, a folder gets inserted into my URL path, and it is rendered as something like:

http://www.example.org/portal/Page1.aspx

It is funny that there is no a single keyword as "portal" in my project, so I end up with a 404 Not Found page.

  • What is causing it? Can this be a policy defined in IIS by admin?
  • It works fine locally, but it happens when I upload it to a server.
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
amit kohan
  • 1,612
  • 2
  • 25
  • 47
  • 1
    Looks like AppDir is getting replaced. Are you sure that's the code you're using? What is the value of currentURL? Do you have any rewrite rules etc? – mason Mar 14 '17 at 17:11
  • have you tried to debug this line? ```string url =``` – tym32167 Mar 14 '17 at 17:11
  • Did you check the value of currentURL? Is your app hosted in IIS under a "portal" folder? – StfBln Mar 14 '17 at 17:11
  • Mason, thanks for your response. I'm using `string currentURL = HttpContext.Current.Request.Url.Host;` and that gives me the host name always – amit kohan Mar 14 '17 at 17:14
  • StfBln, yes I did and watched it in runtime and it is OK. – amit kohan Mar 14 '17 at 17:15
  • not clear if your redirect is just to a different folder on the same website. i assume not, but you probably know that you don't need the full url if that is the case – O. Gungor Mar 14 '17 at 18:05
  • O. Gungor, would you please explain more about it? I will appreciate it. – amit kohan Mar 15 '17 at 17:04
  • tym32167, yes I have traced it. it is just two lines and all the variables are showing up properly in debug time. I believe something on the server forcing it. – amit kohan Mar 15 '17 at 17:38

1 Answers1

0

The admin has admitted that the DNS does it. Not sure, why but it detects it as an invalid URL so it replaces the folder name with a pre-defined name.

amit kohan
  • 1,612
  • 2
  • 25
  • 47
  • I think this is not a very technical question now after finding the reason. Can/should I remove this thread? – amit kohan Mar 16 '17 at 16:54