Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 17th, 2007, 04:49 PM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default FileInfo Class Path Problem

My problem is that my application properly pulls an ASP.NET file on my machine using Visual Web Developer 2005, but it doesn't pull it properly when a copy of the application was uploaded to our test server. On my machine, I listed the entire path for the ASP.NET doc to be pulled (c:\Documents and Settings\MYUSERNAME\My Documents\Visual Studio 2005\Projects\DIRECTORY\SUBDIRECTORY\PAGE.aspx). On the test server, I'm attempting to pull the ASP.NET doc with a UNC share (\\SERVERNAME\DIRECTORY\SUBDIRECTORY\PAGE.aspx).

I'm using the FileInfo Class to do this, and I've included the two versions of code below. If anyone could please let me know what I'm doing wrong, that would be great. (Hopefully it's something obvious) Thanks.

OLD METHOD ON MACHINE:

Code:
Partial Class MasterPage
    Inherits System.Web.UI.MasterPage
    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        'Assign page path to string value
        Dim strPagePath = Request.ServerVariables("PATH_INFO")
        Response.Write("<strong>strPagePath: </strong>" & strPagePath & "<br />") 'test

        'Assign full page path
        Dim strFullPagePath = "c:\Documents and Settings\MYUSERNAME\My Documents\Visual Studio 2005\Projects" & strPagePath

        'Assign path to FileInfo Class
        Dim fi As FileInfo = New FileInfo(strFullPagePath)
        Dim strPageId As String, strPathNoFileName As String
        Dim strXMLPath_mc As String, strXSLPath_mc As String, strCSSPath As String

        'Check if files exist
        If Not fi.Exists Then
            strPageId = "default"
            strPathNoFileName = "http://localhost:1309/DIRECTORYNAME"
        Else
            strPageId = fi.Name.Replace(fi.Extension, "") 'without extension
            strPathNoFileName = strPagePath.Replace(fi.Name, "")
            'Assign dynamic page paths
            strXMLPath_mc = strPathNoFileName + "docs/xml/" & strPageId & ".xml" 'xml doc
            strXSLPath_mc = strPathNoFileName + "docs/xslt/" & strPageId & ".xsl" 'xsl doc
            strCSSPath = strPathNoFileName + "docs/css/" & strPageId & ".css" 'css doc
        End If
    End Sub
End Class
RESULTING VALUE:
strFullPagePath = "c:\Documents and Settings\MYUSERNAME\My Documents\Visual Studio 2005\Projects\DIRECTORY\SUBDIRECTORY\PAGE.aspx"


NEW METHOD ON TEST SERVER:

Code:
Partial Class MasterPage
    Inherits System.Web.UI.MasterPage
    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        'Assign page path to string value
        Dim strPagePath = Request.ServerVariables("PATH_INFO")
    Dim strPagePath_fi As String = strPagePath.Replace("/", "\") 'replace slash
    Dim strFullPagePath = "\\SERVERNAME\DIRECTORY" & strPagePath_fi '<---THIS IS THE PROBLEM

        'Assign path to FileInfo Class
        Dim fi As FileInfo = New FileInfo(strFullPagePath)
        Dim strPageId As String, strPathNoFileName As String
        Dim strXMLPath_mc As String, strXSLPath_mc As String, strCSSPath As String

        'Check if files exist
        If Not fi.Exists Then
            strPageId = "default"
        strPathNoFileName = "http://SERVERNAME/DIRECTORY"
        Else
            strPageId = fi.Name.Replace(fi.Extension, "") 'without extension
            strPathNoFileName = strPagePath.Replace(fi.Name, "")
            'Assign dynamic page paths
            strXMLPath_mc = strPathNoFileName + "docs/xml/" & strPageId & ".xml" 'xml doc
            strXSLPath_mc = strPathNoFileName + "docs/xslt/" & strPageId & ".xsl" 'xsl doc
            strCSSPath = strPathNoFileName + "docs/css/" & strPageId & ".css" 'css doc
        End If
    End Sub
End Class
RESULTING VALUE:
strFullPagePath = "\\SERVERNAME\DIRECTORY\SUBDIRECTORY\PAGE.aspx "

KWilliams
Reply With Quote
  #2 (permalink)  
Old April 17th, 2007, 05:54 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I see what your doing and I have noted where in your code you having a problem, except I dont know what your specific problem is other then you can't pull the file.

Is the runtime throwing an error? Is the file just not being displayed? Are you using impersonation for your application? Can the test server "see" the unc path?

Please clarifiy. ^^

P.S. for a little humor in that this app only works on your machine:
http://www.codinghorror.com/blog/archives/000818.html

Curtosity of gbianchi's profile ^^

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Reply With Quote
  #3 (permalink)  
Old April 17th, 2007, 09:23 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Can you explain further what you mean by "pulls the file"?

What exactly are you trying to accomplish? I can't really tell by reading the code.

There is an inherent problem with testing web apps in VS2005. When you run the app (assuming you are using the typical process) it's running in the ASP.NET test web server application. This is started with you "run" from visual studio. The test web server runs under the authority of the user you are logged in as. In a deployed scenario, IIS is running under a system account. There is a significant difference between the behavior of the app because of this. If you are trying to access network (files) you have success when you test run it in the debugger. But when deployed the runtime identity (the system account) has no rights to access the network resource.

One way to test this is to set up the app to mimic the deployed environment. Point it at a networked file, and run the app under IIS on your dev machine (assuming you have it installed). This is about the only way you can confirm that things are behaving correctly before you deploy the app.

-Peter
Reply With Quote
  #4 (permalink)  
Old April 18th, 2007, 09:24 AM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:dparsons wrote: I see what your doing and I have noted where in your code you having a problem, except I dont know what your specific problem is other then you can't pull the file.

Is the runtime throwing an error? Is the file just not being displayed? Are you using impersonation for your application? Can the test server "see" the unc path?

Please clarifiy. ^^
Quote:
quote: Can you explain further what you mean by "pulls the file"?

What exactly are you trying to accomplish? I can't really tell by reading the code.

There is an inherent problem with testing web apps in VS2005. When you run the app (assuming you are using the typical process) it's running in the ASP.NET test web server application. This is started with you "run" from visual studio. The test web server runs under the authority of the user you are logged in as. In a deployed scenario, IIS is running under a system account. There is a significant difference between the behavior of the app because of this. If you are trying to access network (files) you have success when you test run it in the debugger. But when deployed the runtime identity (the system account) has no rights to access the network resource.

One way to test this is to set up the app to mimic the deployed environment. Point it at a networked file, and run the app under IIS on your dev machine (assuming you have it installed). This is about the only way you can confirm that things are behaving correctly before you deploy the app.

-Peter
I apologize for not being more clear on what I'm needing help with. I have a complicated setup, and I wanted to keep the post simple.

My Setup
I have a MasterPage setup that works with the FileInfo Class. Once I've pulled in the requested page's path (aka "pulls the file") using Dim strPagePath = Request.ServerVariables("PATH_INFO"), I first check to see if the requested file exists on the test server using the FileInfo Class. If it does exist, that file is then loaded. If it does not exist, the home page is loaded as a default. This is the section of code that does this:
Code:
'Check if files exist
If Not fi.Exists Then
    strPageId = "default"
    strPathNoFileName = "http://SERVERNAME/DIRECTORY"
Else
    strPageId = fi.Name.Replace(fi.Extension, "") 'without extension
    strPathNoFileName = strPagePath.Replace(fi.Name, "")
    'Assign dynamic page paths
    strXMLPath_mc = strPathNoFileName + "docs/xml/" & strPageId & ".xml" 'xml doc
    strXSLPath_mc = strPathNoFileName + "docs/xslt/" & strPageId & ".xsl" 'xsl doc
    strCSSPath = strPathNoFileName + "docs/css/" & strPageId & ".css" 'css doc        
End If
...which resulted in the following:
strFullPagePath: \\SERVERNAME\DIRECTORY\SUBDIRECTORY\PAGE.aspx
strXMLPath_mc: /DIRECTORY/docs/xml/DEFAULTPAGE.xml
strXSLPath_mc: /DIRECTORY/docs/xslt/DEFAULTPAGE.xsl
strCSSPath: /DIRECTORY/docs/css/DEFAULTPAGE.css

Each individual file uses the MasterPage to pull up the page's content using a XML/XSLT transformation on-the-fly. The MasterPage loads a central XML doc that contains all of the site's page properties, and pulls only the nodes where the page's id matches the "id" node within that central XML doc.

Current Status
Here's some good news. I removed the If Not fi.Exists...Else statement to see if the requested ASP.NET page would load, and it actually did. This is what the code looks like:
Code:
'Check if files exist
'If Not fi.Exists Then
    'strPageId = "default"
    'strPathNoFileName = "http://SERVERNAME/DIRECTORY"
'Else
    strPageId = fi.Name.Replace(fi.Extension, "") 'without extension
    strPathNoFileName = strPagePath.Replace(fi.Name, "")
    'Assign dynamic page paths
    strXMLPath_mc = strPathNoFileName + "docs/xml/" & strPageId & ".xml" 'xml doc
    strXSLPath_mc = strPathNoFileName + "docs/xslt/" & strPageId & ".xsl" 'xsl doc
    strCSSPath = strPathNoFileName + "docs/css/" & strPageId & ".css" 'css doc        
'End If
...which resulted in the following:
strFullPagePath: \\SERVERNAME\DIRECTORY\SUBDIRECTORY\PAGE.aspx
strXMLPath_mc: /DIRECTORY/SUBDIRECTORY/docs/xml/PAGE.xml
strXSLPath_mc: /DIRECTORY/SUBDIRECTORY/docs/xslt/PAGE.xsl
strCSSPath: /DIRECTORY/SUBDIRECTORY/docs/css/PAGE.css

It's able to manipulate the file path using this class, but it can't see that the file actually exists.

I really like that I can check to see if the file exists, and redirect the user to a default page if it does not. So I'm not sure how I can accomplish that with my current setup. If you could help me out with that, that would be great.

These are the two ways I've tried to pull the requested file from the site for the FileInfo Class:

Dim strFullPagePath = "\\SERVERNAME\DIRECTORY\SUBDIRECTORY\PAGE.aspx "
Dim strFullPagePath = "z:\SERVERNAME\DIRECTORY\SUBDIRECTORY\PAGE.asp x"

I hope my clarification helps to answer your questions. Let me know if it doesn't, or if you have others. And thanks again for your help.

KWilliams
Reply With Quote
  #5 (permalink)  
Old April 18th, 2007, 10:26 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I'm still have no understanding what you are trying to accomplish. Perhaps this analogy would help:

Instead of telling me:

   "I'm trying to mix together flour, water, eggs and yeast to yield a spongy off-white edible substance."

Try explaining it this way:

   "I'm trying to make bread."

You have posted lots of code and explained some very detailed things... but I still don't understand the goal you are trying to reach. If you explain that, you might find (through our suggestions) that there is a far simpler way of reaching that goal.

What it sounds like to me is that you are writing some kind of custom 404 error check routine.

-Peter
Reply With Quote
  #6 (permalink)  
Old April 18th, 2007, 10:49 AM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, hopefully this is clear. I'm trying to see if the requested file exists on the server. If it does exist, the individual XML, XSLT and CSS docs are loaded. If it does not exist, then the default XML, XSLT and CSS docs are loaded (i.e. the home page).

But since the manipulation of the filename using the FileInfo Class is working for me, I'll have to go about checking if the file exists in a different way. Any suggestions would be appreciated.

KWilliams
Reply With Quote
  #7 (permalink)  
Old April 18th, 2007, 11:14 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I see that you are getting the file page with the PATH_INFO server variable. That leads me to believe that you are expecting to receive a direct request for a page that may not exist:

http://yourserver/yourApp/nonExistantPage.aspx

This should raise a 404 error, which you can configure in the web.config to point to your default page.

Given that a 404 error should be coming up, how do you have your app/server configured such that the code ever gets a chance to execute for a non existent page?

What am I missing?

-Peter
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Class library folder path arunkhushi C# 1 February 4th, 2008 12:59 PM
Error while setting class path sujithmathew Linux 1 August 3rd, 2007 01:02 PM
Combining *.csv files sing FileInfo class mhite05 C# 0 October 25th, 2005 09:53 AM
Class path setting pedr0 BOOK: Beginning Java 2 5 July 26th, 2004 03:36 PM



All times are GMT -4. The time now is 10:24 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.