国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
NET中關(guān)于偽靜態(tài)的實(shí)現(xiàn)方法
讓我們仔細(xì)看一下那些優(yōu)秀網(wǎng)站的網(wǎng)址,我們會(huì)發(fā)現(xiàn)他們都是有一定的規(guī)則的,比如按產(chǎn)品分:http://www.abc.com/prod/1.html,按用戶分:http://www.abc.com/user/2.html, 這樣的網(wǎng)址看上去比較友好,至少比http://www.abc.com/user.aspx?id=3這樣要友好的多.那么我們現(xiàn)在就可以思考一下,這是怎么實(shí)現(xiàn)的.
  這里要用到的關(guān)鍵技術(shù)是URL重寫技術(shù),咋一聽,比較復(fù)雜,實(shí)際上,初次理解,也確實(shí)比較復(fù)雜.MS有一篇介紹這個(gè)原理的文章,大家可以看一下:http://www.microsoft.com/china/msdn/library/webservices/asp.net/URLRewriting.mspx?mfr=true
  最最簡(jiǎn)單的實(shí)現(xiàn),就是從上面的這個(gè)網(wǎng)址上下載MSDNURLRewriting.msi,安裝完成后,就生成了一個(gè)解決方案,里面有實(shí)現(xiàn)的原代碼.通常情況下,這些原代碼可以不用改,直接使用.那么我們共同看一下如果實(shí)現(xiàn)一個(gè)最簡(jiǎn)單的重寫.
1.新建立一個(gè)web項(xiàng)目,添加剛才下載下來(lái)生成的dll.
2.修改web.config,這比較重要,所有的重寫規(guī)則都要在這里寫.
  示例:
在<configuration></configuration>中加入:
     <configSections>
          <section name="RewriterConfig"
type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
     </configSections>
     <RewriterConfig>
          <Rules>
              <RewriterRule>
                   <LookFor>~/(\d{4})/(\d{2})/Default\.aspx</LookFor>
                   <SendTo>~/Default.aspx?ID=$1</SendTo>
              </RewriterRule>
          </Rules>
     </RewriterConfig>
然后在<system.web></system.web>中加入:
<httpHandlers>
   <add verb="*" path="*.aspx"
        type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
</httpHandlers>
最后在地址欄上鍵入:http://localhost/Test/2004/12/News.aspx
效果出來(lái)了。
上面的<LookFor>~/(\d{4})/(\d{2})/News\.aspx</LookFor>這句這正則表達(dá)式URL,即被重寫的URL,而<SendTo>~/Default.aspx?ID=$1</SendTo>這一句為原始URL地址。其中的$1為第一個(gè)正則表達(dá)式值(上面例子為:2004),以此類推,第二個(gè)即為$2

簡(jiǎn)單吧,這就是最簡(jiǎn)單的應(yīng)用了,不過(guò)這已經(jīng)可以滿足了最常見(jiàn)的情況了.但是這種方法有一個(gè)弊端,那就是不能修改域名前面的部分,什么意思呢??我們經(jīng)常會(huì)看到一些網(wǎng)址是類似于這樣的,http://use1.abc.com,這可以理解為一個(gè)用戶在這個(gè)網(wǎng)站上的網(wǎng)址,對(duì)于這種方式,上面的方法就不能實(shí)現(xiàn)了,這要用到兩種技術(shù),泛域名解析+URL重寫.
什么是泛域名解析,這個(gè)網(wǎng)上的解釋很多,我在這里就不多說(shuō)了.在做完泛域名解析后,就可以修改web.config里面的內(nèi)容了,
只需改成下面的樣子就可以了.
<configuration>
   
  <configSections>
  <section name="RewriterConfig"
type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
  </configSections>
 
  <RewriterConfig>
  <Rules>
 
  <RewriterRule>
  <LookFor>~/([a-zA-Z0-9]*)\.aspx</LookFor>
  <SendTo>~/List.aspx?Info=$1</SendTo>
  </RewriterRule>
 
  <RewriterRule>
  <LookFor>~/([a-zA-Z0-9]*)\.html</LookFor>
  <SendTo>~/List.aspx?Info=$1</SendTo>
  </RewriterRule>
 
  <RewriterRule>
  <LookFor>http://([a-zA-Z0-9]*)\.blog\.chp365\.cn/</LookFor>
  <SendTo>~/webuserblog/$1/default.htm</SendTo>
  </RewriterRule>
 
  </Rules>
  </RewriterConfig>
  <system.web>
  <httpModules>
  <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
  </httpModules>
另外,還要在IIS中,添加一個(gè)通配符應(yīng)用程序映射,指到aspx的那個(gè)文件就可以了.
下面我引用一下網(wǎng)友KILLHAND的兩篇文章來(lái)說(shuō)一下如何在實(shí)踐中運(yùn)用.他的文章寫的很好.
UrlReWriter 使用經(jīng)驗(yàn)小結(jié)
#UrlRewriter 是微軟封裝好了的一個(gè)URL重寫組件。使用它可以讓我節(jié)約很多自已開發(fā)的時(shí)間。
好了,開始講述我的應(yīng)用經(jīng)驗(yàn),這只是很菜鳥的經(jīng)驗(yàn),高手就不用看了。
第一步,請(qǐng)從此下載此組件。解壓,把UrlRewriter.dll copy到你的項(xiàng)目 bin 目錄下。
第二步,在Web.config中加入:
<?xml version="1.0" encoding="gb2312" ?>
<configuration>
     <configSections>
          <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
     </configSections>
第二步,加入重寫的規(guī)則節(jié)點(diǎn):
如: 
   <RewriterConfig>
          <Rules>
              <RewriterRule>
                   <LookFor>~/Sell/(.[0-9]*)\.html</LookFor>
                   <SendTo>~/Search/Search_Sell.aspx?id=$1</SendTo>
              </RewriterRule>
              <RewriterRule>
                   <LookFor>~/Sell/Search_Sell\.aspx</LookFor>
                   <SendTo>~/Search/Search_Sell.aspx</SendTo>
              </RewriterRule>
              <RewriterRule>
       <LookFor>~/Buy/(.[0-9]*)\.html</LookFor>
                   <SendTo>~/Search/Search_Buy.aspx?id=$1</SendTo>
              </RewriterRule>
              <RewriterRule>
       <LookFor>~/Buys/(.[0-9]*)\.html</LookFor>
                   <SendTo>~/Buys/Show.aspx?id=$1</SendTo>
              </RewriterRule>
          </Rules>
     </RewriterConfig>
這個(gè)就要根據(jù)你的需要了,如果你對(duì)正則表達(dá)式不熟,那么沒(méi)辦法,要么憑借你的高智商去找其中規(guī)律,稍稍改一下就能為你所用了。呵呵。如果實(shí)在搞不清,那就自己GOOGLE一下正則表達(dá)式吧。(本人開始是參考別人的配置猜的,竟然用對(duì)了,呵呵。后來(lái)還是看了一下相關(guān)資料,發(fā)現(xiàn)這東東很有用。)
第三步,加入模塊配置(寫在<system.web>里面):
如:
 <httpHandlers>
     <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
  </httpHandlers>
(這里表示使用HTTP程序來(lái)處理重寫)
好了,到了現(xiàn)在我們可以試一下看。
于是輸入:http://127.0.0.1:8080/Sell/1.aspx 出現(xiàn)了,呵呵。但是如果所它改為:http://127.0.0.1:8080/Sell/1.html
暈,發(fā)現(xiàn)不行。汗。。。
呵呵,原因是沒(méi)把HTML的解析用 asp.net  的ISAPI來(lái)解析。
辦法是。。。
第四步,在IIS\你的站點(diǎn)\屬性\主目錄\配置\映謝 加入一個(gè)和 aspx 頁(yè)面的配置相同的擴(kuò)展名項(xiàng)。注意“確認(rèn)文件是否存在”不要勾選,否則會(huì)出現(xiàn)找不到文件。
現(xiàn)在再來(lái)試試看。什么?#¥%#¥%#,還是不行。呵呵。不要急,咱們回過(guò)頭再來(lái)看看,原來(lái)在 web.config 中我們沒(méi)有配置 .html 也使用模塊此解析。
第五步,在模塊配置中加入:
  <httpHandlers>
     <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
     <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
  </httpHandlers>
現(xiàn)在總可以了吧,呵呵。終于看到了,興奮吧。不要急,這還只是最簡(jiǎn)單的。如果你的頁(yè)面有回傳。比如說(shuō)放了DATAGRID,有分頁(yè)的,你點(diǎn)到下一頁(yè)就發(fā)現(xiàn),暈倒,又出問(wèn)題了。
這下怎么辦呢,這個(gè)其實(shí)微軟件的網(wǎng)站上就有說(shuō)到,我在這里簡(jiǎn)述一下了。

第六步,加入窗體回傳保持的組件:
在原來(lái)你下載的項(xiàng)目里找到 ActionlessForm.dll 放到你的項(xiàng)目 bin 目錄下。
然后在你的這個(gè)頁(yè)面中加入:
<%@ Register TagPrefix="skm" Namespace="ActionlessForm" Assembly="ActionlessForm" %>
再把你的<Form...>改為:
<skm:Form id="你的表單名" method="post" runat="server">
.....
</skm:Form>
That's All.現(xiàn)在你可以高枕無(wú)憂了。一切如你所愿。
最后,恭祝各位一切順利。
利用UrlRewriter 實(shí)現(xiàn)二級(jí)域名
從上一篇文章,我們可以實(shí)現(xiàn)對(duì)域名后面的那部分進(jìn)行重寫,那么可不可以對(duì)前面那部分進(jìn)行重寫而實(shí)現(xiàn)二級(jí)域名呢?
答案是肯定的。
這樣,首先我們得修改UrlRewriter,怎么修改請(qǐng)參見(jiàn)江大魚的BLog。
1.BaseModuleRewriter.cs
 
protected virtual void BaseModuleRewriter_AuthorizeRequest(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication) sender;
            Rewrite(app.Request.Path, app);
        }
改為
 
protected virtual void BaseModuleRewriter_AuthorizeRequest(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication) sender;
            Rewrite(app.Request.Url.AbsoluteUri, app);
        }

就是將  app.Request.Path 替換成了  app.Request.Url.AbsoluteUri
2.ModuleRewriter.cs
 
for(int i = 0; i < rules.Count; i++)
            {
                // get the pattern to look for, and Resolve the Url (convert ~ into the appropriate directory)
                string lookFor = "^" + RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, rules[i].LookFor) + "$";
 
                // Create a regex (note that IgnoreCase is set)
                Regex re = new Regex(lookFor, RegexOptions.IgnoreCase);
 
                // See if a match is found
                if (re.IsMatch(requestedPath))
                {
                    // match found - do any replacement needed
                    string sendToUrl = RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, re.Replace(requestedPath, rules[i].SendTo));
 
                    // log rewriting information to the Trace object
                    app.Context.Trace.Write("ModuleRewriter", "Rewriting URL to " + sendToUrl);
 
                    // Rewrite the URL
                    RewriterUtils.RewriteUrl(app.Context, sendToUrl);
                    break;        // exit the for loop
                }
            }
改為
 
for(int i = 0; i < rules.Count; i++)
            {
                // get the pattern to look for, and Resolve the Url (convert ~ into the appropriate directory)
                string lookFor = "^" + rules[i].LookFor + "$";
 
                // Create a regex (note that IgnoreCase is set)
                Regex re = new Regex(lookFor, RegexOptions.IgnoreCase);
 
                // See if a match is found
                if (re.IsMatch(requestedPath))
                {
                    // match found - do any replacement needed
                    string sendToUrl = RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, re.Replace(requestedPath, rules[i].SendTo));
 
                    // log rewriting information to the Trace object
                    app.Context.Trace.Write("ModuleRewriter", "Rewriting URL to " + sendToUrl);
 
                    // Rewrite the URL
                    RewriterUtils.RewriteUrl(app.Context, sendToUrl);
                    break;        // exit the for loop
                }
            }
string lookFor = "^" + RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, rules[i].LookFor) + "$";
改成了
string lookFor = "^" + rules[i].LookFor + "$";

完成這2處改動(dòng)之后重新編譯項(xiàng)目,將生成的dll復(fù)制到bin目錄下。
修改完了這后,我們?cè)侔汛?UrlRewriter.dll COPY 到我們項(xiàng)目的Bin目錄下。這樣就結(jié)了么?沒(méi)有。
首先請(qǐng)確定你的項(xiàng)目之前有按我上篇文章中寫到的那樣做過(guò)UrlRewriter的配置,否則請(qǐng)先回過(guò)頭來(lái)看看那篇文章。
如果你的項(xiàng)目已配置過(guò),那么,我們還要為此做以下幾件事情:
1。請(qǐng)確定你的域名是支持泛解析的。然后你的網(wǎng)站為默認(rèn)網(wǎng)站,否則將不能實(shí)現(xiàn)(至少我現(xiàn)在還沒(méi)有找到好辦法)
2。在IIS配置:在IIS\你的站點(diǎn)\屬性\主目錄\配置\映謝 在通配符應(yīng)用程序配置處插入一個(gè)新的映謝。把可執(zhí)行文件設(shè)為和上面ASPX頁(yè)面同樣的配置即可(注意不要勾選 “確定文件是否存在”)。(用處就是使所有請(qǐng)求通過(guò) asp.net 的ISAPI來(lái)處理,只有這樣才能對(duì)所有地址進(jìn)行重寫嘛。)
3。查看下你的網(wǎng)站主機(jī)頭,里面的第一個(gè)主機(jī)頭值必須為空,否則會(huì)出現(xiàn)錯(cuò)誤的請(qǐng)求。后面就隨你加了,看你想綁定多少域名了。(這個(gè)辦法是江大魚想出來(lái)的。為這個(gè)錯(cuò)誤我們都想了好多辦法。在這里感謝江大魚。。。)
4。最后改寫你的 web.config 文件。
把上節(jié)中說(shuō)到的
  <httpHandlers>
     <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
     <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
  </httpHandlers>
改為:
  <httpModules>
   <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
  </httpModules>
(就是改用HTTP 模塊來(lái)執(zhí)行重寫,而不用HTTP 程序,否則無(wú)法重寫地址前面。)
然后就來(lái)修改我們的重寫正則了:
              <RewriterRule>
                   <LookFor>http://(.[0-9]*)\.178b2b\.com/</LookFor>
                   <SendTo>~/Search/Search_Sell.aspx?id=$1</SendTo>
              </RewriterRule>
好了,現(xiàn)在你輸入 http://1.178b2b.com/ 就能搜索出相應(yīng)分類了。但是聰明的你馬上就發(fā)現(xiàn)。暈死,首頁(yè)進(jìn)不去了。呵呵。當(dāng)然嘍。你還得為首頁(yè)加入重寫正則。
              <RewriterRule>
                   <LookFor>http://www\.178b2b\.com/</LookFor>
                   <SendTo>~/index.htm</SendTo>
              </RewriterRule>
大功告成。感覺(jué)爽死了吧。呵呵。莫急,如果你二級(jí)域名指向的目錄下面的頁(yè)面都用的相對(duì)地址連接的圖片和其它頁(yè)面的話,呵呵,你有得忙了,你要全部改成如下方式:
<a href=http://www.178b2b.com/cxlm/league.html target="_blank">誠(chéng)信聯(lián)盟</a>
以上就是用UrlRewriter實(shí)現(xiàn)二級(jí)域名的方法了。希望各位一切順利。
最后,感謝江大魚的無(wú)私幫助。

再次對(duì)KILLHEAD和江大魚表示感謝.
說(shuō)的不是很清楚,那是因?yàn)槲椅墓P不好,如果有朋友想共同研究一下的話,可以加我QQ:120854833.或email給我:chenghp986@sohu.com
 
本文來(lái)自CSDN博客,出處:http://blog.csdn.net/chenghp/archive/2007/04/10/1559212.aspx
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
.net實(shí)現(xiàn)URL重寫,偽靜態(tài)。IIS7直接支持重寫模塊
偽靜態(tài)web.config配置步驟
asp.net 用偽靜態(tài)
ASP.NET網(wǎng)站偽靜態(tài)下使用中文URL的方法
在 ASP.NET 中執(zhí)行 URL 重寫
ASP.NET下用URLRewriter重寫二級(jí)域名
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服