Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The role of ASP.NET virtual file system

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "the function of ASP.NET virtual file system". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the role of ASP.NET virtual file system".

The specific implementation steps are as follows:

First, develop web user control

This step is no different from previous development.

1. First create a new web application (VS2005 sp1 support is required)

2. Then develop some web user controls in it

3. Right-click on the ascx file-> Properties-> generate operation to select embedded resources

4. Just generate dll (the name of dll is Test.Control.dll, which will be used later)

Second, develop a virtual file system to provide classes

This step is the most important step.

The specific idea is: register this class in the system, and then automatically call this class every time you access a file / resource, in this class to determine whether the path of the file is defined by us, if it is to use our logic to deal with it, that is, to take resources out of dll.

First of all, post the code of the class. I think maybe many people, like me, like to look at the code first:

DllVirtualPathProvider

Public class DllVirtualPathProvider: System.Web.Hosting.VirtualPathProvider

{

Public DllVirtualPathProvider ()

{

}

Public override string CombineVirtualPaths (string basePath, string relativePath)

{

If (IsAppResourcePath (basePath))

{

Return null

}

Return Previous.CombineVirtualPaths (basePath, relativePath)

}

Public override System.Runtime.Remoting.ObjRef CreateObjRef (Type requestedType)

{

Return Previous.CreateObjRef (requestedType)

}

Public override bool DirectoryExists (string virtualDir)

{

If (IsAppResourcePath (virtualDir))

{

Return true

}

Else

{

Return Previous.DirectoryExists (virtualDir)

}

}

Public override string GetCacheKey (string virtualPath)

{

If (IsAppResourcePath (virtualPath))

{

Return null

}

Else

{

Return Previous.GetCacheKey (virtualPath)

}

}

Public override string GetFileHash (string virtualPath

IEnumerable virtualPathDependencies)

{

If (IsAppResourcePath (virtualPath))

{

Return null

}

Else

{

Return Previous.GetFileHash (virtualPath, virtualPathDependencies)

}

}

Private bool IsAppResourcePath (string virtualPath)

{

String checkPath = VirtualPathUtility.ToAppRelative (virtualPath)

Return checkPath.StartsWith ("~ / MyUserControl/Test.Control.dll/"

StringComparison.InvariantCultureIgnoreCase)

}

Public override bool FileExists (string virtualPath)

{

Return (IsAppResourcePath (virtualPath) | | Previous.FileExists (virtualPath))

}

Public override VirtualFile GetFile (string virtualPath)

{

If (IsAppResourcePath (virtualPath))

{

Return new AssemblyResourceVirtualFile (virtualPath)

}

Else

{

Return Previous.GetFile (virtualPath)

}

}

Public override System.Web.Caching.CacheDependency GetCacheDependency (string virtualPath

System.Collections.IEnumerable virtualPathDependencies, DateTime utcStart)

{

If (IsAppResourcePath (virtualPath))

{

String path = HttpRuntime.AppDomainAppPath + virtualPath.Substring (1)

Return new System.Web.Caching.CacheDependency (path)

}

Else

{

Return Previous.GetCacheDependency (virtualPath, virtualPathDependencies, utcStart)

}

}

}

Thank you for your reading, the above is the content of "the role of ASP.NET virtual file system", after the study of this article, I believe you have a deeper understanding of the role of ASP.NET virtual file system, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report