473,794 Members | 2,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with VirtualPathProv ider

Help...wimper.. been trying to get a virtualpathprov ider to work and I have
to be missing something. I want users to be able to enter something like
mydomain.com/userentereddire ctory/ and have that serve up a file. So I use
vpp to code up an initialization even, virturalfile, virtualdirector y 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/userentereddire ctory - 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\Visua l Studio 2005\WebSites\H uningtonManor\9 26'
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>RegisterP rovider</i></b>
Namespace HuntingtonManor .Framework

Public Class AppStart

Public Shared Sub AppInitialize()
Dim DynamicProvider As DynamicPathProv ider = New
DynamicPathProv ider()
HostingEnvironm ent.RegisterVir tualPathProvide r(DynamicProvid er)
End Sub

End Class
End Namespace

<b><i>VirtualPa thProvider</i></b>

Namespace HuntingtonManor .Framework
<AspNetHostingP ermission(Secur ityAction.Deman d,
Level:=AspNetHo stingPermission Level.Medium), _
AspNetHostingPe rmission(Securi tyAction.Inheri tanceDemand,
level:=AspNetHo stingPermission Level.High)> _
Public Class DynamicPathProv ider
Inherits VirtualPathProv ider

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

Protected Overrides Sub Initialize()
End Sub

Private Function IsPathVirtual(B yVal virtualPath As String) As Boolean
'Return True
Dim checkPath As String
checkPath = VirtualPathUtil ity.ToAppRelati ve(virtualPath)
Return checkPath.Start sWith("~/926",
StringCompariso n.InvariantCult ureIgnoreCase)
End Function

Public Overrides Function FileExists(ByVa l virtualPath As String) As
Boolean
If (IsPathVirtual( virtualPath)) Then
Dim file As DynamicVirtualF ile
file = CType(GetFile(v irtualPath), DynamicVirtualF ile)
'Return file.Exists
Return True
Else
Return Previous.FileEx ists(virtualPat h)
End If
End Function

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

Dim dir As DynamicVirtualD irectory
dir = CType(GetDirect ory(virtualDir) , DynamicVirtualD irectory)
'Return dir.exists
Return True
Else
Return Previous.Direct oryExists(virtu alDir)
End If

End Function

Public Overrides Function GetDirectory(By Val virtualDir As String)
As System.Web.Host ing.VirtualDire ctory
If (IsPathVirtual( virtualDir)) Then
Return New DynamicVirtualD irectory(virtua lDir, Me)
Else
Return Previous.GetDir ectory(virtualD ir)
End If

End Function

Public Overrides Function GetFile(ByVal virtualPath As String) As
System.Web.Host ing.VirtualFile
If (IsPathVirtual( virtualPath)) Then
Return New DynamicVirtualF ile(virtualPath , Me)
Else
Return Previous.GetFil e(virtualPath)
End If

End Function

End Class
End Namespace

<b><i>VirtualFi leProvider</b></i>
Namespace HuntingtonManor .Framework
<AspNetHostingP ermission(Secur ityAction.Deman d,
Level:=AspNetHo stingPermission Level.Minimal), _
AspNetHostingPe rmission(Securi tyAction.Inheri tanceDemand,
level:=AspNetHo stingPermission Level.Minimal)> _
Public Class DynamicVirtualF ile
Inherits VirtualFile

Private spp As DynamicPathProv ider

Public Sub New(ByVal virtualPath As String, ByVal provider As
DynamicPathProv ider)
MyBase.New(virt ualPath)
spp = provider
End Sub

Public Overrides Function Open() As System.IO.Strea m

'this is the file I want to serve
Dim templateFile As String
templateFile = HostingEnvironm ent.Application PhysicalPath &
"tester.asp x"

Dim pageTemplate As String
pageTemplate = My.Computer.Fil eSystem.ReadAll Text(templateFi le)

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

Dim writer As StreamWriter
writer = New StreamWriter(st ream)

writer.Write(pa geTemplate)
writer.Flush()
stream.Seek(0, SeekOrigin.Begi n)

Return stream
End Function
End Class
End Namespace

<b><i>VirtualDi rectoryProvider </i></b>
Namespace HuntingtonManor .Framework
<AspNetHostingP ermission(Secur ityAction.Deman d,
Level:=AspNetHo stingPermission Level.Minimal), _
AspNetHostingPe rmission(Securi tyAction.Inheri tanceDemand,
level:=AspNetHo stingPermission Level.Minimal)> _
Public Class DynamicVirtualD irectory
Inherits VirtualDirector y

Private spp As DynamicPathProv ider

' 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
DynamicPathProv ider)
MyBase.New(virt ualDir)
spp = provider

End Sub

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

Private directoriesValu e As ArrayList
Public Overrides ReadOnly Property Directories() As
System.Collecti ons.IEnumerable
Get
Return directoriesValu e
End Get
End Property

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

End Namespace

<b><i>Tester.as px</i></b>
<%@ Page Language="VB" %>

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

<script runat="server">

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed 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 1556

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

Similar topics

117
7273
by: Peter Olcott | last post by:
www.halting-problem.com
28
5224
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(); .... and then call the virtual method, why is it that the base class's method is called instead of the overridden method? How do I fix this if I don't know at runtime what the child class is? I'm using Activator.CreateInstance() to load the...
6
3815
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 is more that 1249 bytes, then the progress bar of the browser will move too slow and then displaying that the page not found!!!! If the message is less than or equal to 1249 then no problem.
16
4930
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 Microsoft must be installed on their servers. Now german Umlaute (ä, ü, ö) and quotes are returned incorrectly in SOAP fault responses. This can be easily verified: Implement the following in a web service method (just raises a SOAPException with a...
0
1381
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"); it return true if file ucDataPager.ascx control exists, but if I publish web site (no editable) and .ascx files not available on the disc, this method return false, its bug?
1
1687
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. Please, what I'm missing?! VV
0
1244
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 VirtualPathProvider and VirtualFile classes to do this. However, the mimetype of the response is 'application/ octet-stream'. I want it to be 'text/xml'. Changing HttpContext.Current.Response.ContentType does not affect the
0
1269
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 not recognized unless I rebuild all. Could somebody explain why this is happening? I presume it has something to do with the page being compiled and put into a cache but I cannot figure out how to change the behavior. I can find nothing that...
5
2866
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 question is: How could I access session variables from class that derives from VirtualPathProvider or VirtualFile or the control values of previous web page?
0
9518
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10433
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10212
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10161
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9035
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6777
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2919
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.