VirtualPathProvider problem

Last post 09-04-2007 6:11 PM by fabio.medeiros. 10 replies.

Sort Posts:

  • VirtualPathProvider problem

    08-29-2007, 7:24 AM
    • Member
      4 point Member
    • fabio.medeiros
    • Member since 08-27-2007, 3:51 PM
    • Brazil, Sao Paulo, Barueri
    • Posts 9

    Hello everyone. This is my first post, and I apologize if I make any mistake. My English is not very good, so I apologize about this too.

    My question is about the VirtualPathProvider - I made a test project using this option, and it works fine, except in one case.

    I have a real folder in the path ~/test/one/ and the real files ~/test/one/Default.aspx and ~/test/one/Agenda.aspx

    I want that any URL like ~/test/two/Agenda.aspx (no real folder exists, only a virtual), points to ~/test/one/Agenda.aspx and so on.

    As I wrote the code, it is working when I try to access ~/test/two/Agenda.aspx and ~/test/two/Default.aspx , but when I try to access ~/test/two/ (should open Default.aspx) it brings the asp code opened, I mean, no asp tag is interpreted. The tag <% response.write("x") %> comes exactly like this in the HTML source.

    I am writing down the project code:

    If it helps, download http://www.sportcv.net/Download/VirtualPath.zip (5 Kbytes)

    Global.asax
    <%@ Application Language="VB" %>

    <script runat="server">

        Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
           
    ' Code that runs on application startup
            Dim meuProvider As Espaço.clsPathProvider = New Espaço.clsPathProvider()
            System.Web.Hosting.HostingEnvironment.RegisterVirtualPathProvider(meuProvider)
       
    End Sub
       
       
    Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
           
    ' Code that runs on application shutdown
        End Sub
           
       
    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
           
    ' Code that runs when an unhandled error occurs
        End Sub

        Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
           
    ' Code that runs when a new session is started
        End Sub

        Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
           
    ' Code that runs when a session ends.
            ' Note: The Session_End event is raised only when the sessionstate mode
            ' is set to InProc in the Web.config file. If session mode is set to StateServer
            ' or SQLServer, the event is not raised.
        End Sub
          
    </script>

    Default.aspx
    <%@ Page Language="VB" AutoEventWireup="false" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <
    html xmlns="http://www.w3.org/1999/xhtml" >
    <
    head runat="server">
        <title>Untitled Page</title>
    </
    head>
    <
    body>
        <form id="form1" runat="server">
        <div>
       
           
    <asp:HyperLink runat=server ID=Zero Text="one/Default.aspx" NavigateUrl="~/test/one/Default.aspx"></asp:HyperLink><br />
            <br />
            <span style="font-size: 10pt; font-family: Verdana">
            Root:<br />
            </span>
            <asp:HyperLink runat=server ID=one Text=one NavigateUrl="~/test/one/"></asp:HyperLink><span
                style="font-size: 10pt; font-family: Verdana"> &lt;- Working<br />
            </span>
            <asp:HyperLink runat=server ID=two Text=two NavigateUrl="~/test/two/"></asp:HyperLink><span
                style="font-size: 10pt; font-family: Verdana"> &lt;- <span style="color: red"><strong>
                    <span style="text-decoration: underline">Not working fine</span></strong><br />
                </span>
            </span>
            <asp:HyperLink runat=server ID=three Text=three NavigateUrl="~/test/three/"></asp:HyperLink><span
                style="font-size: 10pt; font-family: Verdana"> &lt;- <span style="color: #ff0000;
                    text-decoration: underline"><
    strong>Not working fine</strong></span><br />
            </span>
            <asp:HyperLink runat=server ID=four Text=four NavigateUrl="~/test/four/"></asp:HyperLink><span
                style="font-size: 10pt; font-family: Verdana"> &lt;- <span style="color: #ff0000;
                    text-decoration: underline"><
    strong>Not working fine</strong></span><br />
            <br />
            Default:<br />
            </span>
            <asp:HyperLink runat=server ID=HyperLink5 Text=one NavigateUrl="~/test/one/Default.aspx"></asp:HyperLink><span
                style="font-size: 10pt; font-family: Verdana"> &lt;- Working<br />
            </span>
            <asp:HyperLink runat=server ID=HyperLink6 Text=two NavigateUrl="~/test/two/Default.aspx"></asp:HyperLink><span
                style="font-size: 10pt; font-family: Verdana"> &lt;- Working<br />
            </span>
            <asp:HyperLink runat=server ID=HyperLink7 Text=three NavigateUrl="~/test/three/Default.aspx"></asp:HyperLink><span
                style="font-size: 10pt; font-family: Verdana"> &lt;- Working<br />
            </span>
            <asp:HyperLink runat=server ID=HyperLink8 Text=four NavigateUrl="~/test/four/Default.aspx"></asp:HyperLink><span
                style="font-size: 10pt; font-family: Verdana"> &lt;- Working<br />
            <br />
            Agenda:<br />
            </span>
            <asp:HyperLink runat=server ID=HyperLink1 Text=one NavigateUrl="~/test/one/Agenda.aspx"></asp:HyperLink><span
                style="font-size: 10pt; font-family: Verdana"> &lt;- Working<br />
            </span>
            <asp:HyperLink runat=server ID=HyperLink2 Text=two NavigateUrl="~/test/two/Agenda.aspx"></asp:HyperLink><span
                style="font-size: 10pt; font-family: Verdana"> &lt;- Working<br />
            </span>
            <asp:HyperLink runat=server ID=HyperLink3 Text=three NavigateUrl="~/test/three/Agenda.aspx"></asp:HyperLink><span
                style="font-size: 10pt; font-family: Verdana"> &lt;- Working<br />
            </span>
            <asp:HyperLink runat=server ID=HyperLink4 Text=four NavigateUrl="~/test/four/Agenda.aspx"></asp:HyperLink><span
                style="font-size: 10pt; font-family: Verdana"> &lt;- Working<br />
            </span>
           
       
    </div>
        </form>
    </
    body>
    </
    html>

    App_Code/clsVirtual.vb
    Imports Microsoft.VisualBasic
    Imports System.Web.Hosting
    Imports System.IO

    Namespace Espaço

       
    Public Class clsVirtualFile
           
    Inherits VirtualFile

           
    Private fullPath As String

            Public Sub New(ByVal virtualPath As String, ByVal realPath As String)

               
    MyBase.New(virtualPath)

               
    Dim lstrAux As String = VirtualPathUtility.ToAppRelative(virtualPath)

               
    'ex: "~/test/two/app_something/abc.aspx"
                lstrAux = Mid(lstrAux, InStr(lstrAux, "/") + 1) 'now "test/two/app_something/abc.aspx"
                lstrAux = Mid(lstrAux, InStr(lstrAux, "/") + 1) 'now "two/app_something/abc.aspx"
                lstrAux = Mid(lstrAux, InStr(lstrAux, "/") + 1) 'now "app_something/abc.aspx"

                lstrAux = realPath & Replace(lstrAux, "/", "\")

                fullPath = lstrAux

               
    If File.Exists(fullPath) = False Then
                    If Directory.Exists(fullPath) Then
                        fullPath = Path.Combine(fullPath, "Default.aspx")
                   
    End If
                End If

            End Sub

            Public ReadOnly Property Exists() As Boolean
                Get
                    Dim lblnReturnVariable As Boolean = File.Exists(fullPath)
                   
    Return lblnReturnVariable
               
    End Get
            End Property

            Public Overrides Function Open() As System.IO.Stream

               
    Return File.OpenRead(fullPath)

               
    'Dim pageTemplate As String

                'pageTemplate = My.Computer.FileSystem.ReadAllText(fullPath)

                '' Put the page content on the stream.
                'Dim stream As MemoryStream
                'stream = New MemoryStream()

                'Dim writer As StreamWriter
                'writer = New StreamWriter(stream)

                'writer.Write(pageTemplate)
                'writer.Flush()
                'stream.Seek(0, SeekOrigin.Begin)

                'Return stream

            End Function
        End Class

        Public Class clsVirtualDirectory
           
    Inherits VirtualDirectory

           
    Private fullPath As String

            Public Sub New(ByVal virtualDir As String, ByVal realPath As String)

               
    MyBase.New(virtualDir)

               
    Dim lstrAux As String = VirtualPathUtility.ToAppRelative(VirtualPath)

               
    'ex: "~/test/two/app_something/"
                lstrAux = Mid(lstrAux, InStr(lstrAux, "/") + 1) 'Fica "test/two/app_something/"
                lstrAux = Mid(lstrAux, InStr(lstrAux, "/") + 1) 'Fica "two/app_something/"
                lstrAux = Mid(lstrAux, InStr(lstrAux, "/") + 1) 'Fica "app_something/"

                lstrAux = realPath & Replace(lstrAux, "/", "\")

                fullPath = lstrAux

               
    'If File.Exists(fullPath) = False Then
                '    If Directory.Exists(fullPath) Then
                '        fullPath = Path.Combine(fullPath, "Default.aspx")
                '    End If
                'End If

            End Sub

            Public ReadOnly Property Exists() As Boolean
                Get
                    Dim lblnReturnVariable As Boolean = Directory.Exists(fullPath)
                   
    Return lblnReturnVariable
               
    End Get
            End Property

            Public Overrides ReadOnly Property Children() As System.Collections.IEnumerable

               
    Get

                    Dim childDirectories() As String = Directory.GetDirectories(fullPath)
                   
    Dim childFiles() As String = Directory.GetFiles(fullPath)
                   
    Dim ReturnVariable As New System.Collections.Generic.List(Of String)

                    ReturnVariable.AddRange(childDirectories)
                    ReturnVariable.AddRange(childFiles)

                   
    Return ReturnVariable

               
    End Get

            End Property

            Public Overrides ReadOnly Property Directories() As System.Collections.IEnumerable
               
    Get
                    Return Directory.GetDirectories(fullPath)
               
    End Get
            End Property

            Public Overrides ReadOnly Property Files() As System.Collections.IEnumerable
               
    Get
                    Return Directory.GetFiles(fullPath)
               
    End Get
            End Property
        End Class

        Public Class clsPathProvider
           
    Inherits VirtualPathProvider

           
    Private Const pathReal As String = "~/test/one/"
            Dim mstrPathReal As String = ""

            Public Sub New()

               
    MyBase.New()

                mstrPathReal = System.AppDomain.CurrentDomain.BaseDirectory

               
    If InStr(mstrPathReal, "/") > 0 Then
                    If Right(mstrPathReal, 1) <> "/" Then
                        mstrPathReal &= "/"
                    End If
                    mstrPathReal &= "test/one/"
                Else
                    If Right(mstrPathReal, 1) <> "\" Then
                        mstrPathReal &= "\"
                    End If
                    mstrPathReal &= "test/one\"
                End If

                'If File.Exists(mstrPathReal) = False Then
                '    If Directory.Exists(mstrPathReal) Then
                '        mstrPathReal = Path.Combine(mstrPathReal, "Default.aspx")
                '    End If
                'End If

            End Sub

            Private Function IsPathVirtual(ByVal VirtualPath As String) As Boolean

                Dim checkPath As String

                checkPath = VirtualPathUtility.ToAppRelative(VirtualPath)
               
    Return checkPath.StartsWith("~/test", StringComparison.InvariantCultureIgnoreCase)

           
    End Function

            Public Overrides Function FileExists(ByVal virtualPath As String) As Boolean

                Dim lblnReturnVariable As Boolean = False

                If (IsPathVirtual(virtualPath)) Then
                    Dim lclsVirtualFile As New clsVirtualFile(virtualPath, mstrPathReal)
                   
    'file = CType(GetFile(virtualPath), clsVirtualFile)
                    lblnReturnVariable = lclsVirtualFile.Exists
                    lclsVirtualFile =
    Nothing
                Else
                    lblnReturnVariable = Previous.FileExists(virtualPath)
               
    End If

                Return lblnReturnVariable

           
    End Function

            Public Overrides Function DirectoryExists(ByVal virtualDir As String) As Boolean

                Dim lblnReturnVariable As Boolean = False

                If (IsPathVirtual(virtualDir)) Then
                    Dim lclsVirtualDirectory As New clsVirtualDirectory(virtualDir, mstrPathReal)
                   
    'dir = CType(GetDirectory(virtualDir), clsVirtualDirectory)
                    lblnReturnVariable = lclsVirtualDirectory.Exists
                    lclsVirtualDirectory =
    Nothing
                Else
                    lblnReturnVariable = Previous.DirectoryExists(virtualDir)
               
    End If

                Return lblnReturnVariable

           
    End Function

            Public Overrides Function GetFile(ByVal virtualPath As String) As VirtualFile

               
    Dim lvflReturnVariable As VirtualFile

               
    If (IsPathVirtual(virtualPath)) Then
                    lvflReturnVariable = New clsVirtualFile(virtualPath, mstrPathReal)
               
    Else
                    lvflReturnVariable = Previous.GetFile(virtualPath)
                
    End If

                Return lvflReturnVariable

           
    End Function

            Public Overrides Function GetDirectory(ByVal virtualDir As String) As VirtualDirectory

               
    Dim lvdrReturnVariable As VirtualDirectory

               
    If (IsPathVirtual(virtualDir)) Then
                    lvdrReturnVariable = New clsVirtualDirectory(virtualDir, mstrPathReal)
               
    Else
                    lvdrReturnVariable = Previous.GetDirectory(virtualDir)
               
    End If

                Return lvdrReturnVariable

            
    End Function

            Public Overrides Function GetCacheDependency(ByVal virtualPath As String, _
                                                        
    ByVal virtualPathDependencies As IEnumerable, _
                                                        
    ByVal utcStart As Date) As CacheDependency

               
    Dim dependency As CacheDependency

               
    If (IsPathVirtual(virtualPath)) Then

                    dependency = New CacheDependency(mstrPathReal)

               
    Else
                    dependency = Previous.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart)

               
    End If

                Return dependency

           
    End Function

        End Class

    End
    Namespace

    test/one/Default.aspx
    <%@ Page Language="VB" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <
    script runat="server">

    </
    script>

    <
    html xmlns="http://www.w3.org/1999/xhtml" >
    <
    head runat="server">
        <title>Untitled Page</title>
    </
    head>
    <
    body>
        <form id="form1" runat="server">
        <div>
        <% Response.Write(Request.Url.ToString)%><br />
        <% Response.Write(Format(Now, "dd/MM/yyyy HH:mm:ss"))%><br />
       
       
    <asp:HyperLink runat=server ID=Home Text=Back NavigateUrl="~/Default.aspx"></asp:HyperLink><br />
        This is a Default page<br />

        </div>
        </form>
    </
    body>
    </
    html>

    test/one/Agenda.aspx
    <%@ Page Language="VB" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <
    script runat="server">

    </
    script>

    <
    html xmlns="http://www.w3.org/1999/xhtml" >
    <
    head runat="server">
        <title>Untitled Page</title>
    </
    head>
    <
    body>
        <form id="form1" runat="server">
        <div>
        <% Response.Write(Request.Url.ToString)%><br />
        <% Response.Write(Format(Now, "dd/MM/yyyy HH:mm:ss"))%><br />
       
       
    <asp:HyperLink runat=server ID=Home Text=Back NavigateUrl="~/Default.aspx"></asp:HyperLink><br />
        This is an Agenda page<br />

        </div>
        </form>
    </
    body>
    </
    html>

  • Re: VirtualPathProvider problem

    08-30-2007, 10:08 AM
    • Member
      4 point Member
    • fabio.medeiros
    • Member since 08-27-2007, 3:51 PM
    • Brazil, Sao Paulo, Barueri
    • Posts 9
    Did I put this topic in the right place? No answer about the problem… (???)
  • Re: VirtualPathProvider problem

    08-31-2007, 3:16 PM

    Hi Fabio.

    I'd suggest posting this in the Configuration or Deployment section of ASP.NET forums, as this isn't exactly specific to building custom server controls.

    Hope your post will be answered there.

  • Re: VirtualPathProvider problem

    09-02-2007, 1:04 PM
    • Member
      4 point Member
    • fabio.medeiros
    • Member since 08-27-2007, 3:51 PM
    • Brazil, Sao Paulo, Barueri
    • Posts 9

    OK Max

    I will try there. Once I have an answer there, I close both topics as "answered".

    Thanks for your tip. 

    -- EDIT --

    Moved the thread to Configuration and Deployment.

    - joteke

  • Re: VirtualPathProvider problem

    09-03-2007, 6:29 AM

    Hi fabio.medeiros,

    Thank you for posting the clear demo. However, I have to tell you that this issue is by design and doesn’t have any workaround.

    When we input the path instead of the real file, such as http://localhost/VirtualPath, IIS will try to find if there is a default page defined in IIS metabase. If such file doesn’t exist, IIS will try to list the files in the required folder, if the folder doesn’t exist at all, “HTTP 404 - File not found” error will be raised.

    For example, when you try to browse http://localhost/VirtualPath/test/one/, IIS will search the metabase to check if there has any default page. If the file exists (such as Default.aspx), IIS will route the request to ASP.NET worker process, then ASP.NET will know the request and handle it as expected. However, if the file doesn’t exist, IIS will not route the request to ASP.NET worker process and directly response to client with error message, so that ASP.NET totally doesn’t know the request.

    To clarify this issue, please do a test with following steps in IIS manager:

        1. Right click the “VirtualPath” node and then select “Properties”.
        2. Go to “Documents” tab, uncheck the “Enable Default Document” option, or delete the “Default.aspx” item.
        3. Try to browse: http://localhost/VirtualPath/test/one/, it will give the “HTTP 403” error (“Directory browsing” option unchecked) or list the contents of the folder.

    Why does http://localhost/VirtualPath/test/two/Default.aspx work well? It’s is because in IIS mappings, the file which extension is aspx will be routed to “c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll”, so this request will be route to ASP.NET worker process directly, then it will be redirect to the correct page by  your clsVirtualFile class.

     

    Sincerely,
    Benson Yu
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help. This can be beneficial to other community members reading the thread.
  • Re: VirtualPathProvider problem

    09-03-2007, 1:05 PM
    • Member
      4 point Member
    • fabio.medeiros
    • Member since 08-27-2007, 3:51 PM
    • Brazil, Sao Paulo, Barueri
    • Posts 9

    Benson Yu - MSFT:

    When we input the path instead of the real file, such as http://localhost/VirtualPath, IIS will try to find if there is a default page defined in IIS metabase. If such file doesn’t exist, IIS will try to list the files in the required folder, if the folder doesn’t exist at all, “HTTP 404 - File not found” error will be raised.

    Uhhmmm...

    But, in my test project, I don't receive this error... When I access .../VirtualPath/test/one/ it brings the default.aspx (as you explained). However, when I call .../VirtualPath/test/two/ the default.aspx is also showed, but it comes "open", I mean, all asp tags are shown inside the html source.

    I will thing about some way to bypass this problem, and someone may have another good idea.

    Tks anyway.

  • Re: VirtualPathProvider problem

    09-03-2007, 8:25 PM

    I've tried this thing, with not only VirtualFile but VirtualDirectory too, only to find out that a request for something like http://localhost/WebSite/ would call the method FileExists(...) of the VirtualPathProvider, and later GetFile if the exists returns true. So, you should manually check for a directory in FileExists and GetFile, (using methods of the VirtualPathUtility if you have to) to manually direct ASP.NET to Default.aspx, as it's out of IIS' hands (with "Default Documents") by then.

  • Re: VirtualPathProvider problem

    09-04-2007, 12:45 PM
    Answer
    • Member
      4 point Member
    • fabio.medeiros
    • Member since 08-27-2007, 3:51 PM
    • Brazil, Sao Paulo, Barueri
    • Posts 9
    I wrote a “pseudo” default page to solve this problem.
    First I changed the …/test/one/default.aspx :

    <%@ Page Language="VB" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <
    script runat="server">

    </
    script>

    <
    html xmlns="http://www.w3.org/1999/xhtml" >
    <
    head runat="server">
        <title>Untitled Page</title>
    </
    head>
    <
    body>
    <
    iframe
    src="PseudoDefault.aspx"
    width="100%"
    frameborder=no
    scrolling=no
    marginheight=0
    marginwidth=0
    >
    </
    iframe>
    <
    br />
    </
    body>
    </
    html>

    I put an IFRAME that calls the PseudoDefault.aspx. It could be done as a normal frame, but I chose the iframe by personal reasons.

    This is the …/test/one/PseudoDefault.aspx: (almost the same old Default.aspx)
    <%@ Page Language="VB" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

    </script>

    <
    html xmlns="http://www.w3.org/1999/xhtml" >
    <
    head runat="server">
        <title>Untitled Page</title>
    </
    head>
    <
    body>
        <form id="form1" runat="server">
        <div>
        <% Response.Write(Request.Url.ToString)%><br />
        <% Response.Write(Format(Now, "dd/MM/yyyy HH:mm:ss"))%><br />
       
       
    <asp:HyperLink runat=server ID=Home Text=Back NavigateUrl="~/Default.aspx" Target=_top></asp:HyperLink><br />
        This is a Pseudo Default page<br />

        </div>
        </form>

    </
    body>
    </
    html>

    The only difference is the “Target” of the hyperlink. It must be “_top”.

    The source code is updated in http://www.sportcv.net/Download/VirtualPath.zip


    Thank you people.

  • Re: VirtualPathProvider problem

    09-04-2007, 1:00 PM
    • Member
      4 point Member
    • fabio.medeiros
    • Member since 08-27-2007, 3:51 PM
    • Brazil, Sao Paulo, Barueri
    • Posts 9

    I don't know why the format is this way. I tried several times to make it better, but it always became worse. I will not try again... sorry...

     -- edit --

    Max helped me and the format is ok now. Tks Max Yes

  • Re: VirtualPathProvider problem

    09-04-2007, 4:33 PM

    Fabio,

    What exactly are you trying to achieve at this point? You said the problem was in that requests to a virtual directory path (that is, something like http://localhost/WebSite/Directory) would not map correctly to a Default.aspx served upon a request such as http://localhost/WebSite/Directory/Default.aspx, then as I've said, a directory request would go directly into FileExists() and GetFile(), supplying the request string as argument. Then, you should programmatically direct a directory request as such to the file Default.aspx, because IIS no longer affects it using its default documents. It's forwarded the request to ASP.NET ISAPI, and let it run.

    Also, to format code correctly, paste it into word first, replace all paragraph marks with line breaks (using replace ^p with ^l) to make the code not look double-spaced, and if necessary, all tabs with 2 spaces, (the tab character is ^t).

    Hope this helps. 

  • Re: VirtualPathProvider problem

    09-04-2007, 6:11 PM
    • Member
      4 point Member
    • fabio.medeiros
    • Member since 08-27-2007, 3:51 PM
    • Brazil, Sao Paulo, Barueri
    • Posts 9

    Max Kukartsev:

    ... then as I've said, a directory request would go directly into FileExists() and GetFile(), supplying the request string as argument. Then, you should programmatically direct a directory request as such to the file Default.aspx, ...

    Yes. I've already done this. In the VirtualFile class:

        Public Class clsVirtualFile
           
    Inherits VirtualFile

           
    Private fullPath As String

            Public Sub New(ByVal virtualPath As String, ByVal realPath As String)

               
    MyBase.New(virtualPath)

               
    Dim lstrAux As String = VirtualPathUtility.ToAppRelative(virtualPath)

               
    'ex: "~/test/two/app_something/abc.aspx"
                lstrAux = Mid(lstrAux, InStr(lstrAux, "/") + 1) 'now "test/two/app_something/abc.aspx"
                lstrAux = Mid(lstrAux, InStr(lstrAux, "/") + 1) 'now "two/app_something/abc.aspx"
                lstrAux = Mid(lstrAux, InStr(lstrAux, "/") + 1) 'now "app_something/abc.aspx"

                lstrAux = realPath & Replace(lstrAux, "/", "\")

                fullPath = lstrAux

               
    If File.Exists(fullPath) = False Then
                    If Directory.Exists(fullPath) Then
                        fullPath = Path.Combine(fullPath, "Default.aspx")
                   
    End If
                End If

            End Sub

            Public ReadOnly Property Exists() As Boolean
                Get
                    Dim lblnReturnVariable As Boolean = File.Exists(fullPath)
                   
    Return lblnReturnVariable
               
    End Get
            End Property

            Public Overrides Function Open() As System.IO.Stream

               
    Return File.OpenRead(fullPath)

           
    End Function

        End Class

    the most relevant step is this:

                If File.Exists(fullPath) = False Then
                    If Directory.Exists(fullPath) Then
                        fullPath = Path.Combine(fullPath, "Default.aspx")
                   
    End If
                End If

    I verify if the file exists. If not, I verify if the directory exists. If it exists, I assign the default.aspx file.

    The FileExists() and GetFile() are also coded:

        Public Class clsPathProvider
            Inherits VirtualPathProvider

            ...

            Public Overrides Function FileExists(ByVal virtualPath As String) As Boolean

                Dim lblnReturnVariable As Boolean = False

                If (IsPathVirtual(virtualPath)) Then
                    Dim lclsVirtualFile As New clsVirtualFile(virtualPath, mstrPathReal)
                    'file = CType(GetFile(virtualPath), clsVirtualFile)
                    lblnReturnVariable = lclsVirtualFile.Exists
                    lclsVirtualFile = Nothing
                Else
                    lblnReturnVariable = Previous.FileExists(virtualPath)
                End If

                Return lblnReturnVariable

            End Function

            Public Overrides Function GetFile(ByVal virtualPath As String) As VirtualFile

                Dim lvflReturnVariable As VirtualFile

                If (IsPathVirtual(virtualPath)) Then
                    lvflReturnVariable = New clsVirtualFile(virtualPath, mstrPathReal)
                Else
                    lvflReturnVariable = Previous.GetFile(virtualPath)
                End If

                Return lvflReturnVariable

            End Function

    The problem was the default.aspx was comming, but it comes "open" (sorry about my poor English), no asp tag is interpreted. If you download the project and try to run it you will understand...

    I had marked this topic as "Resolved", but if anybody wants to keep it open, it is ok to me.

Page 1 of 1 (11 items)