472,328 Members | 1,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

Problem with VirtualPathProvider

Help...wimper.. been trying to get a virtualpathprovider to work and I have
to be missing something. I want users to be able to enter something like
mydomain.com/userentereddirectory/ and have that serve up a file. So I use
vpp to code up an initialization even, virturalfile, virtualdirectory and
virtualpath provider. I have a simple file for testing testing.aspx (no
codebehind) that just sets a label to 'hello world' on pageload. Now when I
debug and just to go mydomain.com/userentereddirectory - I get the text that
makes up my tester.aspx file return but its not compiled or executed - if i
specify mydomaing.com/user../tester.aspx I get 'Directory 'C:\Documents and
Settings\Ken\My Documents\Visual Studio 2005\WebSites\HuningtonManor\926'
does not exist. Failed to start monitoring file changes.' Can't figure out
what I'm doing wrong - I looked at all the tutorials out there and everything
seems to be working as it should?! Code to follow.. All code is in app_code
- now I merely hardcoded 926 as the begining to test for a virtual directory
- just tryng to make this work before i put in my true implementation.

<b><i>RegisterProvider</i></b>
Namespace HuntingtonManor.Framework

Public Class AppStart

Public Shared Sub AppInitialize()
Dim DynamicProvider As DynamicPathProvider = New
DynamicPathProvider()
HostingEnvironment.RegisterVirtualPathProvider(Dyn amicProvider)
End Sub

End Class
End Namespace

<b><i>VirtualPathProvider</i></b>

Namespace HuntingtonManor.Framework
<AspNetHostingPermission(SecurityAction.Demand,
Level:=AspNetHostingPermissionLevel.Medium), _
AspNetHostingPermission(SecurityAction.Inheritance Demand,
level:=AspNetHostingPermissionLevel.High)> _
Public Class DynamicPathProvider
Inherits VirtualPathProvider

Public Sub New()
MyBase.New()
End Sub

Protected Overrides Sub Initialize()
End Sub

Private Function IsPathVirtual(ByVal virtualPath As String) As Boolean
'Return True
Dim checkPath As String
checkPath = VirtualPathUtility.ToAppRelative(virtualPath)
Return checkPath.StartsWith("~/926",
StringComparison.InvariantCultureIgnoreCase)
End Function

Public Overrides Function FileExists(ByVal virtualPath As String) As
Boolean
If (IsPathVirtual(virtualPath)) Then
Dim file As DynamicVirtualFile
file = CType(GetFile(virtualPath), DynamicVirtualFile)
'Return file.Exists
Return True
Else
Return Previous.FileExists(virtualPath)
End If
End Function

Public Overrides Function DirectoryExists(ByVal virtualDir As
String) As Boolean
If (IsPathVirtual(virtualDir)) Then

Dim dir As DynamicVirtualDirectory
dir = CType(GetDirectory(virtualDir), DynamicVirtualDirectory)
'Return dir.exists
Return True
Else
Return Previous.DirectoryExists(virtualDir)
End If

End Function

Public Overrides Function GetDirectory(ByVal virtualDir As String)
As System.Web.Hosting.VirtualDirectory
If (IsPathVirtual(virtualDir)) Then
Return New DynamicVirtualDirectory(virtualDir, Me)
Else
Return Previous.GetDirectory(virtualDir)
End If

End Function

Public Overrides Function GetFile(ByVal virtualPath As String) As
System.Web.Hosting.VirtualFile
If (IsPathVirtual(virtualPath)) Then
Return New DynamicVirtualFile(virtualPath, Me)
Else
Return Previous.GetFile(virtualPath)
End If

End Function

End Class
End Namespace

<b><i>VirtualFileProvider</b></i>
Namespace HuntingtonManor.Framework
<AspNetHostingPermission(SecurityAction.Demand,
Level:=AspNetHostingPermissionLevel.Minimal), _
AspNetHostingPermission(SecurityAction.Inheritance Demand,
level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class DynamicVirtualFile
Inherits VirtualFile

Private spp As DynamicPathProvider

Public Sub New(ByVal virtualPath As String, ByVal provider As
DynamicPathProvider)
MyBase.New(virtualPath)
spp = provider
End Sub

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

'this is the file I want to serve
Dim templateFile As String
templateFile = HostingEnvironment.ApplicationPhysicalPath &
"tester.aspx"

Dim pageTemplate As String
pageTemplate = My.Computer.FileSystem.ReadAllText(templateFile)

' 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
End Namespace

<b><i>VirtualDirectoryProvider</i></b>
Namespace HuntingtonManor.Framework
<AspNetHostingPermission(SecurityAction.Demand,
Level:=AspNetHostingPermissionLevel.Minimal), _
AspNetHostingPermission(SecurityAction.Inheritance Demand,
level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class DynamicVirtualDirectory
Inherits VirtualDirectory

Private spp As DynamicPathProvider

' Declare the variable the property uses.
Private existsValue As Boolean

Public ReadOnly Property exists() As Boolean
Get
Return existsValue
End Get
End Property

Public Sub New(ByVal virtualDir As String, ByVal provider As
DynamicPathProvider)
MyBase.New(virtualDir)
spp = provider

End Sub

Private childrenValue As ArrayList
Public Overrides ReadOnly Property Children() As
System.Collections.IEnumerable
Get
Return childrenValue
End Get
End Property

Private directoriesValue As ArrayList
Public Overrides ReadOnly Property Directories() As
System.Collections.IEnumerable
Get
Return directoriesValue
End Get
End Property

Private filesValue As ArrayList
Public Overrides ReadOnly Property Files() As
System.Collections.IEnumerable
Get
Return filesValue
End Get
End Property
End Class

End Namespace

<b><i>Tester.aspx</i></b>
<%@ 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">

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
Me.Label1.Text = "blah blah blah"
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></div>
</form>
</body>
</html>


Apr 30 '06 #1
0 1464

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

117
by: Peter Olcott | last post by:
www.halting-problem.com
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer...
0
by: Pavel Kocar | last post by:
Hi all, how to detect existing .ascx control in Net 2.0? I try to use method in VirtualPathProvider:...
1
by: VV | last post by:
I've created virtualpathprovider class in my application. Everything is ok in developer enviroment (asp.net dev server), but when I switch to IIS...
0
by: forge1968 | last post by:
I want to handle URLs like this on my IIS site: http://localhost/myapp/REST/foo/1 ('REST/foo/1' doesn't exist - I'll dynamically create the...
0
by: Shane | last post by:
Hello, I'm using VirtualPathProvider for a CMS-like system. As soon as I register the VPP I can no longer debug code with a normal Build -- any...
5
by: Charles Zhang | last post by:
I am creating dynamic web pages according to the user inputs from a web page. For instance, a user typed in a text, I would want the text being...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.