Link to home
Start Free TrialLog in
Avatar of aspnetdev
aspnetdev

asked on

Problem with Request.ApplicationPath

Hi,
I have following function

if ((userName == null) || (userName.Length <= 0))
{
   string login = Request.ApplicationPath + "/login.aspx";
   string js = string.Format ("<script langauge=\"javascript\">window.parent.location.href = '{0}';</script>",login);
   this.RegisterStartupScript("login", js);  
}

this works fine with my localhost and windows xp but on windows 2000  string login = Request.ApplicationPath + "/login.aspx"; gives only http://login.aspx instead of the whole application path/login.aspx.....does anyone know why Request.ApplicationPath  is not able to get the path on windows 2000 and how can one resolve this.
Thanks
Avatar of YZlat
YZlat
Flag of United States of America image

try replacing

Request.ApplicationPath
with

Server.MapPath(Request.ApplicationPath)
Avatar of ethoths
ethoths

WHen you talk about the differente machines do you mean clients or have you installed your web on these servers?

If the latter have you configured the application correctly in IIS?

Forget YZlat answer. This will return the physical (folder) location of the app!
Avatar of aspnetdev

ASKER

basically windows2000 is my staging server....i have iis installed there too....and i copied all my dlls and aspx pages anf everything works fine except this Request.ApplicationPath...i heard that  in windows 2000 you can create multiple defaults sites unlinke xp where u have one default site...underwhich u create the virtual dir...im confused
These are not clients ....i have installed my app there...its server by itself
You can use something like the following:

string strURL = "http://"+Request.ServerVariables["SERVER_NAME"]+"/"+Request.ServerVariables["URL"];
string strScriptPath = Request.ServerVariables["SCRIPT_NAME"];
string[] strScriptPathArr = strScriptPath.Split('/');
string strScriptName = strScriptPathArr[strScriptPathArr.Length - 1];
strURL = strURL.Replace(strScriptName,"")+"/login.aspx";

--Nauman.

did you try using CurrentExecutionFilePath instead?
In 2000 just put your site as a folder in c:\inetpub\wwwroot\MyApp

The in IIS click on the create application button.
Nauman ,i tried your solution but ,if im in like http://MyDir/Sub1/Sub2/test.aspx,then its redirecting me to
http://MyDir/Sub1/Sub2/login.aspx instead of  http://MyDir/login.aspx
Nauman ...i can be in  http://MyDir/Sub1/Sub2/Sub3/test1.aspx,yours solution is getting me
 http://MyDir/Sub1/Sub2/login.aspx rather than  http://MyDir/login.aspx....can you please reply asap.TY
ASKER CERTIFIED SOLUTION
Avatar of nauman_ahmed
nauman_ahmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Iam using this way ...and implementing it on win2k server

string userName = UtpContextManager.UserName;
 if ((userName == null) || (userName.Length <= 0))
  {
     string login;
     if(Request.ApplicationPath == null)
      {
          loginFile = "http://"+Request.ServerVariables["SERVER_NAME"]+"/login.aspx";
       }
     else
      {
         login = Request.ApplicationPath + "/login.aspx";
      }
 
  string js = string.Format ("<script langauge=\"javascript\">window.parent.location.href = '{0}';</script>",login);
   this.RegisterStartupScript("login", js);  

Let me try it ...and if this works 500 are yours :)
actually its seems that on win2k server the directory structure is different ...unlinke winxp where we get http://servername/website  in win2k its http://servername/page.aspx   the website name is not there....anyways let me implement n see..how it goes and then will get back to u
ty
im checking for Request.ApplicationPath since win2k's apppath is always null "it seems" and other server does have the Request.ApplicationPath....hope it works