|
Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
|
Tradução
Original
|
VirtualPathProvider Classe
Assembly: System.Web (em System.Web. dll)
Páginas ASP.NET, as páginas mestras, controles de usuário e outros objetos. Páginas da Web padrão com extensões, como .htm e JPG. Any custom extension mapped to a BuildProvider instance. Any named theme in the App_Theme folder.
O Global. Arquivo ASAX. Arquivos Web.config. Site map data files used by the XmlSiteMapProvider. Diretórios que contêm os conjuntos de módulos do aplicativo ou que geram conjuntos de módulos (assemblies) do aplicativo: Bin, App_Code, App_GlobalResources, any App_LocalResources. The application data folder, App_Data.
Observação: |
|---|
Registrando um VirtualPathProvider
Observação: |
|---|
Criar Um aplicativo exemplo no seu servidor Web. Copy the source code for the custom VirtualPathProvider object (see below) into a file in the application's App_Code directory. Copy the source code for the custom VirtualDirectory object (see the Example section in the VirtualDirectory class overview topic) into a file in the application's App_Code directory. Copy the source code for the custom VirtualFile object (see the Example section in the VirtualFile class overview topic) into a file in the application's App_Code directory. Copy the source code for the AppStart object (see below) into a file in the application's App_Code directory. Copy the XML data (see below) into a file named XMLData.xml into a file in the application's App_Data directory. Copy the default.aspx file (see below) into the root directory of the sample application. Use a Web browser to open the default.aspx file, and then click the links on the page to see the contents of the virtual files.
System;
System.Data;
System.Security.Permissions;
System.Web;
System.Web.Caching;
System.Web.Hosting;
Samples.AspNet.CS
{
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Medium)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.High)]
SamplePathProvider : VirtualPathProvider
{
string dataFile;
SamplePathProvider()
: ()
{
}
Initialize()
{
dataFile = HostingEnvironment.ApplicationPhysicalPath + ;
}
DataSet GetVirtualData()
{
DataSet ds = (DataSet)HostingEnvironment.Cache.Get();
(ds == )
{
ds = DataSet();
ds.ReadXml(dataFile);
CacheDependency cd = CacheDependency(dataFile);
HostingEnvironment.Cache.Add(, ds, cd,
Cache.NoAbsoluteExpiration,
TimeSpan(0, 20, 0),
CacheItemPriority.Default, );
DateTime dataTimeStamp = DateTime.Now;
HostingEnvironment.Cache.Insert(, dataTimeStamp, ,
Cache.NoAbsoluteExpiration,
TimeSpan(0, 20, 0),
CacheItemPriority.Default, );
}
ds;
}
IsPathVirtual(string virtualPath)
{
String checkPath = VirtualPathUtility.ToAppRelative(virtualPath);
checkPath.StartsWith(, StringComparison.InvariantCultureIgnoreCase);
}
FileExists(string virtualPath)
{
(IsPathVirtual(virtualPath))
{
SampleVirtualFile file = (SampleVirtualFile)GetFile(virtualPath);
file.Exists;
}
Previous.FileExists(virtualPath);
}
DirectoryExists(string virtualDir)
{
(IsPathVirtual(virtualDir))
{
SampleVirtualDirectory dir = (SampleVirtualDirectory)GetDirectory(virtualDir);
dir.Exists;
}
Previous.DirectoryExists(virtualDir);
}
VirtualFile GetFile(string virtualPath)
{
(IsPathVirtual(virtualPath))
SampleVirtualFile(virtualPath, );
Previous.GetFile(virtualPath);
}
VirtualDirectory GetDirectory(string virtualDir)
{
(IsPathVirtual(virtualDir))
SampleVirtualDirectory(virtualDir, );
Previous.GetDirectory(virtualDir);
}
CacheDependency GetCacheDependency(
string virtualPath,
System.Collections.IEnumerable virtualPathDependencies,
DateTime utcStart)
{
(IsPathVirtual(virtualPath))
{
System.Collections.Specialized.StringCollection fullPathDependencies = ;
(string virtualDependency virtualPathDependencies)
{
(fullPathDependencies == )
fullPathDependencies = System.Collections.Specialized.StringCollection();
fullPathDependencies.Add(virtualDependency);
}
(fullPathDependencies == )
;
string[] fullPathDependenciesArray = string[fullPathDependencies.Count];
fullPathDependencies.CopyTo(fullPathDependenciesArray, 0);
string[] virtualPathArray = string[1];
virtualPathArray[0] = virtualPath;
CacheDependency(virtualPathArray, fullPathDependenciesArray, utcStart);
}
Previous.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart);
}
}
<?xml version="1.0" encoding="utf-8" ?>
<resource type="dir"
path="/vrDir"
parentPath=""
content="">
<resource type="file"
path="/vrDir/Level1FileA.vrf"
parentPath="/vrDir"
content="This is the content of file Level1FileA.">
</resource>
<resource type="file"
path="/vrDir/Level1FileB.vrf"
parentPath="/vrDir"
content="This is the content of file Level1FileB.">
</resource>
<resource type="dir"
path="/vrDir/Level2DirA"
parentPath="/vrDir"
content="">
<resource type="file"
path="/vrDir/Level2DirA/Level2FileA.vrf"
parentPath="/vrDir/Level2DirA"
content="This is the content of file Level2FileA.">
</resource>
<resource type="file"
path="/vrDir/Level2DirA/Level2FileB.vrf"
parentPath="/vrDir/Level2DirA"
content="This is the content of file Level2FileB.">
</resource>
</resource>
<resource type="dir"
path="/vrDir/Level2DirB"
parentPath="/vrDir"
content="">
<resource type="file"
path="/vrDir/Level2DirB/Level2FileA.vrf"
parentPath="/vrDir/Level2DirB"
content="This is the content of file Level2FileA.">
</resource>
<resource type="file"
path="/vrDir/Level2DirB/Level2FileB.vrf"
parentPath="/vrDir/Level2DirB"
content="This is the content of file Level2FileB.">
</resource>
</resource>
</resource>
<%@ Page Language= %>
<!DOCTYPE html PUBLIC "-
<script runat=>
</script>
<html xmlns="http:
<head runat=>
<meta http-equiv= content= />
<title>Virtual Path Provider Example</title>
</head>
<body>
<form id= runat=>
<asp:HyperLink ID= runat= NavigateUrl= Text= /><br />
<asp:HyperLink ID= runat= NavigateUrl= Text= /><br />
<asp:HyperLink ID= runat= NavigateUrl= Text= /><br />
<asp:HyperLink ID= runat= NavigateUrl= Text= /><br />
<asp:HyperLink ID= runat= NavigateUrl= Text= /><br />
<asp:HyperLink ID= runat= NavigateUrl= Text= /><br />
</form>
</body>
</html>
- AspNetHostingPermission
Para operar em um ambiente hospedado. Exigem valor: LinkDemand. Valor de permissão: Medium. - AspNetHostingPermission
Para operar em um ambiente hospedado. Exigem valor: InheritanceDemand. Valor de permissão: High.
Observação: