博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Custom VirtualPathProvider
阅读量:5128 次
发布时间:2019-06-13

本文共 1461 字,大约阅读时间需要 4 分钟。

1: using System;
2: using System.Web;
3: using System.Web.Util;
4: using System.Web.Hosting;
5: 
6: public class SimpleVPP : VirtualPathProvider {
7:     public static void AppInitialize() {
8:         HostingEnvironment.RegisterVirtualPathProvider(new SimpleVPP());
9:     }
10: 
11:     public override string CombineVirtualPaths(string basePath, string relativePath) {
12: 
13:         // If the path is relative, let normal processing happen
14:         if (!VirtualPathUtility.IsAbsolute(relativePath))
15:             return base.CombineVirtualPaths(basePath, relativePath);
16:
17:         // Determine the pseudo site from the request.  To demonstrate, we just get it from the
18:         // query string, but it could come from other places, like the http host header
19:         string site = HttpContext.Current.Request.QueryString["site"];
20: 
21:         // If we couldn't, default to normal processing
22:         if (site == null)
23:             return base.CombineVirtualPaths(basePath, relativePath);
24: 
25:         // Make it app relative (i.e. ~/...)
26:         relativePath = VirtualPathUtility.ToAppRelative(relativePath);
27: 
28:         // Remap the virtual path to be inside the correct pseudo site
29:         return "~/PseudoSites/" + site + relativePath.Substring(1);
30:     }
31: }

 

application_start或httpModule里注册再用, 也不是特好用, 但总比其他折腾来的方便多了...

还是Routing好...

转载于:https://www.cnblogs.com/fanweixiao/archive/2009/01/27/1381089.html

你可能感兴趣的文章
steelray project viewer
查看>>
itext jsp页面打印
查看>>
HTTP之报文
查看>>
Perl正则表达式匹配
查看>>
Git
查看>>
DB Change
查看>>
nginx --rhel6.5
查看>>
Eclipse Python插件 PyDev
查看>>
selenium+python3模拟键盘实现粘贴、复制
查看>>
第一篇博客
查看>>
typeof与instanceof的区别
查看>>
网站搭建(一)
查看>>
SDWebImage源码解读之SDWebImageDownloaderOperation
查看>>
elastaticsearch
查看>>
postgreSQL 简单命令操作
查看>>
Spring JDBCTemplate
查看>>
Radon变换——MATLAB
查看>>
第五章笔记
查看>>
Iroha and a Grid AtCoder - 1974(思维水题)
查看>>
gzip
查看>>