Custom VirtualPathProvider

   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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值