0

In my C# Application, inside Application_Start function of Global.asax (D:\inetpub\wwwroot\projectApp\Global.asax), I used Server.MapPath with path as "config\config.cfg".

String absPath = Server.MapPath("config\config.cfg");

It was working correctly, but intermittent, instead of mapping it to

D:\inetpub\wwwroot\projectApp\config\config.cfg,

it maps it to either

D:\inetpub\wwwroot\projectApp\A\config\config.cfg, or, D:\inetpub\wwwroot\projectApp\B\config\config.cfg, or, D:\inetpub\wwwroot\projectApp\C\config\config.cfg,

where A, B, C, are API paths and we use <machine name>/projectApp/<A/B/C> to call them. Why is it happening so?

I changed it to,

String absPath = Server.MapPath(@"~/config/config.cfg");

It seems to be working fine right now. But, can it cause issues later?

ptntialunrlsd
  • 794
  • 8
  • 23
  • Anyone any insights, please? – ptntialunrlsd Feb 12 '15 at 05:20
  • With `String absPath = Server.MapPath(@"~/config/config.cfg")` will be fine. The problem with `String absPath = Server.MapPath("config\config.cfg");` was that it was showing the path relative to the script which is executing. – M. Mennan Kara Feb 12 '15 at 06:45
  • Thanks a lot! But that code is there in Global.asax which is placed in the Appication root (ie, in projectApp directory), and no API calls are done till then, since it executed at the application start. – ptntialunrlsd Feb 12 '15 at 06:54
  • Still, the call initiates the Global.asax to execute, so the mappath will relate to the first requests path. – M. Mennan Kara Feb 12 '15 at 06:55
  • So, is it that the first API call executes Global.asax, and not the Application start from IIS itself? So, how did it work sometimes? – ptntialunrlsd Feb 12 '15 at 07:01
  • First call to your web, it didn't work properly, it mapped it either to A or B or C – M. Mennan Kara Feb 12 '15 at 07:01

0 Answers0