Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Problem with Request.ApplicationPath

Posted on 2006-11-02
13
336 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:aspnetdev
  • 6
  • 3
  • 2
  • +1
13 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 17858656
try replacing

Request.ApplicationPath
with

Server.MapPath(Request.ApplicationPath)
0
 
LVL 11

Expert Comment

by:ethoths
ID: 17858682
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?

0
 
LVL 11

Expert Comment

by:ethoths
ID: 17858692
Forget YZlat answer. This will return the physical (folder) location of the app!
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:aspnetdev
ID: 17858733
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
0
 

Author Comment

by:aspnetdev
ID: 17858739
These are not clients ....i have installed my app there...its server by itself
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 17858750
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.

0
 
LVL 35

Expert Comment

by:YZlat
ID: 17858771
did you try using CurrentExecutionFilePath instead?
0
 
LVL 11

Expert Comment

by:ethoths
ID: 17858777
In 2000 just put your site as a folder in c:\inetpub\wwwroot\MyApp

The in IIS click on the create application button.
0
 

Author Comment

by:aspnetdev
ID: 17859407
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
0
 

Author Comment

by:aspnetdev
ID: 17859519
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
0
 
LVL 25

Accepted Solution

by:
nauman_ahmed earned 500 total points
ID: 17859809
ok..if login.aspx is in the web site root than just use the following:

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

--Nauman.
0
 

Author Comment

by:aspnetdev
ID: 17860066
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
0
 

Author Comment

by:aspnetdev
ID: 17860073
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
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question