隱藏網站尾碼名.aspx

來源:互聯網
上載者:User

method 1 首先添加全域應用程式Global.asax

    protected void Application_BeginRequest(Object sender, EventArgs e)
    {
        string rawUrl = Request.RawUrl;
        rawUrl = rawUrl.Replace("html", "aspx");
        Context.RewritePath(rawUrl);
    }

瀏覽器輸入http://localhost:1981/UrlRewritingTest/Default.html 實際跳轉到Default.aspx

 

method 2

UrlRewriter 是微軟封裝好了的一個URL重寫組件。使用它可以讓我節約很多自已開發的時間。

好了,開始講述我的應用程式經驗,這隻是很菜鳥的經驗,高手就不用看了。

第一步,請從此下載此組件。解壓,把UrlRewriter.dll copy到你的項目 bin 目錄下。

第二步,在Web.config中加入:

<?xml version="1.0" encoding="gb2312" ?>
<configuration>
     <configSections>
          <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
     </configSections>

第二步,加入重寫的規則節點:
如:  
   <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>

這個就要根據你的需要了,如果你對Regex不熟,那麼沒辦法,要麼憑藉你的高智商去找其中規律,稍稍改一下就能為你所用了。呵呵。如果實在搞不清,那就自己GOOGLE一下Regex吧。(本人開始是參考別人的配置猜的,竟然用對了,呵呵。後來還是看了一下相關資料,發現這東東很有用。)

第三步,加入模組配置(寫在<system.web>裡面):
如:
<httpHandlers>
     <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
   </httpHandlers>
(這裡表示使用HTTP程式來處理重寫)

好了,到了現在我們可以試一下看。

於是輸入:http://127.0.0.1:8080/Sell/1.aspx 出現了,呵呵。但是如果所它改為:http://127.0.0.1:8080/Sell/1.html
暈,發現不行。汗。。。
呵呵,原因是沒把HTML的解析用 asp.net 的ISAPI來解析。
辦法是。。。

第四步,在IIS/你的網站/屬性/主目錄/配置/映謝 加入一個和 aspx 頁面的配置相同的副檔名項。注意“確認檔案是否存在”不要勾選,否則會出現找不到檔案。

現在再來試試看。什嗎?#¥%#¥%#,還是不行。呵呵。不要急,咱們回過頭再來看看,原來在 web.config 中我們沒有配置 .html 也使用模組此解析。

第五步,在模組配置中加入:
   <httpHandlers>
     <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
     <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
   </httpHandlers>

現在總可以了吧,呵呵。終於看到了,興奮吧。不要急,這還只是最簡單的。如果你的頁面有回傳。比如說放了DATAGRID,有分頁的,你點到下一頁就發現,暈倒,又出問題了。
這下怎麼辦呢,這個其實微軟體的網站上就有說到,我在這裡簡述一下了。

第六步,加入表單回傳保持的組件:
在原來你下載的項目裡找到 ActionlessForm.dll 放到你的項目 bin 目錄下。

然後在你的這個頁面中加入:
<%@ Register TagPrefix="skm" Namespace="ActionlessForm" Assembly="ActionlessForm" %>
再把你的<Form...>改為:
<skm:Form id="你的表單名" method="post" runat="server">
.....
</skm:Form>

為了您的安全,請只開啟來源可靠的網址

開啟網站    {
share.safelink.close();return false;
}" href="http://writeblog.csdn.net/#">取消

來自: http://hi.baidu.com/guke1991/blog/item/3e1e8b1094bc671ab8127b66.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.