日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
ASP.NET下用URLRewriter重寫二級(jí)域名

這里要求對(duì)域名進(jìn)行重寫,實(shí)現(xiàn)http://1234.abc.com/ 到 ~/Defa.aspx?id=1234的重寫。

***:域名

首先域名要支持泛解悉,就是域名解悉的主機(jī)名為星號(hào)*,例:*.abc.com。如下圖

這樣能保證你在瀏覽器地址欄輸入任何前綴,DNS都會(huì)把它們指向到你指定的IP地址上。

第二:IIS設(shè)置(Win2003 + IIS 6為例)

(1)網(wǎng)站必須為Web服務(wù)器的默認(rèn)站點(diǎn),即端口號(hào)為80,主機(jī)頭為空的站點(diǎn)。如下圖所示。

該站點(diǎn)接收所有對(duì)該服務(wù)器的HTTP請(qǐng)求(其它設(shè)置為主機(jī)頭的站點(diǎn)除外)。所以任何二級(jí)域名訪問該服務(wù)器都會(huì)由該站點(diǎn)進(jìn)行處理。

(2)另外要在站點(diǎn)的“通配符應(yīng)用程序映射”列表中添加ASP.NET的Web請(qǐng)求處理程序aspnet_isapi.dll。如下圖所示。

在這里的設(shè)置,是讓該站點(diǎn)接到的所有請(qǐng)求都交給aspnet_isapi.dll處理。

第三:修改Microsoft的URLRewriter。

運(yùn)行開源項(xiàng)目URLRewriter。這里需要修改兩個(gè)地方:

(1)BaseModuleRewriter.cs類

  
 
 
 
  1.  protected virtual void BaseModuleRewriter_AuthorizeRequest(object sender, EventArgs e) 
  2.  { 
  3.  HttpApplication app = (HttpApplication) sender; 
  4.  //Rewrite(app.Request.Path, app); 
  5. Rewrite(app.Request.Url.AbsoluteUri, app); // ## ## ## 這里修改了 

這里將app.Request.Path 替換成了 app.Request.Url.AbsoluteUri

(2)ModuleRewriter.cs類

  
 
 
 
  1.  protected override void Rewrite(string requestedPath, System.Web.HttpApplication app) 
  2.  { 
  3.  // log information to the Trace object. 
  4.  app.Context.Trace.Write("ModuleRewriter", "Entering ModuleRewriter"); 
  5.  // get the configuration rules 
  6. RewriterRuleCollection rules = RewriterConfiguration.GetConfig().Rules; 
  7. // iterate through each rule... 
  8. for (int i = 0; i < rules.Count; i++) 
  9.  { 
  10.  // get the pattern to look for, and Resolve the Url (convert ~ into the appropriate directory) 
  11.  //string lookFor = "^" + RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, rules[i].LookFor) + "$"; 
  12.  string lookFor = "^" + rules[i].LookFor + "$"; // ## ## ## 這里修改了 
  13. // Create a regex (note that IgnoreCase is set...) 
  14. Regex re = new Regex(lookFor, RegexOptions.IgnoreCase); 
  15. // See if a match is found 
  16. if (re.IsMatch(requestedPath)) 
  17.  { 
  18. // match found - do any replacement needed 
  19. string sendToUrl = RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, re.Replace(requestedPath, rules[i].SendTo)); 
  20.  // log rewriting information to the Trace object 
  21.  app.Context.Trace.Write("ModuleRewriter", "Rewriting URL to " + sendToUrl); 
  22. // Rewrite the URL 
  23.  RewriterUtils.RewriteUrl(app.Context, sendToUrl); 
  24. break; // exit the for loop 
  25.  } 
  26.  } 
  27.  // Log information to the Trace object 
  28.  app.Context.Trace.Write("ModuleRewriter", "Exiting ModuleRewriter"); 

這里將string lookFor = "^" + RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, rules[i].LookFor) + "$";

改成了 string lookFor = "^" + rules[i].LookFor + "$";

這兩個(gè)地方修改完以后,生成項(xiàng)目。將項(xiàng)止目bin/Debug目錄下的URLRewriter.dll文件Copy到我們要重寫URL的項(xiàng)目中。

第四:配置項(xiàng)目

(1)在web.config文件的configSections節(jié)點(diǎn)下添加如下一行代碼

  
 
 
 

這里配置一個(gè)重寫配置的類

(2)修改httpModules節(jié)點(diǎn),在里面添加一行配置代碼

  
 
 
 

(3)在主節(jié)點(diǎn)configuration節(jié)點(diǎn)下添加路由規(guī)則,代碼如下:

  
 
 
 
  1.  
  2.      
  3.      
  4.             
  5. http://(\w+).abc.com/
  6.  ~/Defa.aspx?id=$1
  7.            
  8.   
  9.   
  10.   

代碼里一個(gè)RewriterRule節(jié)點(diǎn)就是一個(gè)規(guī)則,這時(shí)只有一個(gè),即把域名中的主機(jī)頭部分做為Defa.aspx頁面的id參數(shù)的值發(fā)送給Defa.aspx頁面。

注意:這里L(fēng)ookFor節(jié)點(diǎn)里的http://(\w+).abc.com/不能少了***的反斜框

OK,一切完工

發(fā)布,上傳到服務(wù)器,測(cè)試一下,如圖

本次測(cè)試需要一個(gè)類庫:URLRewriter.dll (測(cè)試版本 1.0.1495.18710)

官網(wǎng)下載地址:http://download.microsoft.com/download/0/4/6/0463611e-a3f9-490d-a08c-877a83b797cf/MSDNURLRewriting.msi


網(wǎng)頁標(biāo)題:ASP.NET下用URLRewriter重寫二級(jí)域名
網(wǎng)站URL:http://www.5511xx.com/article/dpscegg.html