473,387 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 1530

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 base class... BaseClass bc = new ChildClass();...
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 the article. The problem is: I the comment length...
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 says service packs marked as "critical" by...
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: HostingEnvironment.VirtualPathProvider.FileExists("~/App_UserControls/ucDataPager.ascx");...
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 everything crashes with Server 500 and 404 error....
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 content). I have implemented my own...
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 changes that I've made since the first build are...
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 the source code of the dynamic page. My...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.