日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

asp.net 用偽靜態(tài)

 看見就非常 2014-07-14

    使用rewrite在iis上設(shè)置規(guī)則來實現(xiàn)偽靜態(tài),這樣在vs中開發(fā)的時候?qū)o法調(diào)試,必須要是用iis發(fā)布才不會造成找不到文件的錯誤,當(dāng)然,肯定還有其他的方法來實現(xiàn)偽靜態(tài)的,不用再iis中設(shè)置任何的東西,只需要一個。net的組件和設(shè)置一下webconfig文件就ok了,來看一下,這東西,我用的次數(shù)很少,每次用都怕忘記,所以記錄下來,下次忘記的話也不用Google啦

      這回的準(zhǔn)備工作,你必須去網(wǎng)上download一個URLRewriter.dll組件了,網(wǎng)上貌似有這個類庫的源代碼,當(dāng)然里面也有編譯好的dll文件,只需要把dll文件coty到自己站點的Bin下面,然后在網(wǎng)站上右鍵,添加引用,瀏覽選擇這個dll文件即可。

     下面就需要在webconfig里面配置一番了

     1、在Web.Config的<system.web>和</system.web>添加以下節(jié)點:
    <httpModules> 
      <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" /> 
    </httpModules> 

    2、在Web.Config的<configuration>和</configuration>添加以下節(jié)點:

<configSections> 
  <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" /> 
</configSections> 
   
 <RewriterConfig>
  <Rules>
   <RewriterRule>
    <LookFor>~/Default/.html</LookFor>
    <SendTo>~/Default.aspx</SendTo>
   </RewriterRule>
   <RewriterRule>
    <LookFor>~/Detial_([0-9]*)/.html</LookFor>
    <SendTo>~/Detial.aspx?Id=$1</SendTo>
   </RewriterRule>
   <RewriterRule>
    <LookFor>~/List_p([0-9]*)/.html</LookFor>
    <SendTo>~/List.aspx?page=$1</SendTo>
   </RewriterRule>
   <RewriterRule>
    <LookFor>~/Double_t([0-9]*)_p([0-9]*)/.html</LookFor>
    <SendTo><!--[CDATA[~/Double.aspx?type=$1&page=$2]]--></SendTo>
   </RewriterRule>
   <RewriterRule>
    <LookFor>~/About_(.*)/.html</LookFor>
    <SendTo>~/About.aspx?title=$1</SendTo>
   </RewriterRule>
  </Rules>
 </RewriterConfig>

設(shè)置完以上兩個步驟,就基本可以運行了,其中<RewriterRule/>標(biāo)簽里面就是重寫的一個模塊,<LookFor/>里面的是重寫后的地址,而<SendTo/>則是原地址。大家應(yīng)該注意到了我寫了2組<RewriterRule/>,其中第一組的是給單參數(shù)的地址用的,而另一組是給多參數(shù)動態(tài)文件用的。

   相信大家如果用過在iis里面配置偽靜態(tài)規(guī)則的話,那在webconfig里面配置規(guī)則自然不在話下,如果不會的話,就去找一些正則表達(dá)式的書看一下,不需要很精通就行

  當(dāng)然此方法有一些注意事項:
1.不能使用Windows身份驗證用戶權(quán)限. 應(yīng)使用Form驗證,在web.config配置為:<authentication mode="Forms" />
2.使用Request.ServerVariables["script_name"]獲得的路徑仍然是:ShowPlay.asp?vid=1
3.被重寫的地址如果回發(fā),重寫將失效 顯示的地址將是ShowPlay.asp?vid=1
4. 后綴名必須為.aspx.如果是其他自定義后綴名,如.net  請在iis將.net映射到aspnet_isapi.dll.

 

五個頁面

About.aspx

    <form id="form1" runat="server">
        <div>
    這是Aboutl頁,url是About.aspx還是About.html?<br/>
    
    <br/>
    <br/>
    <a href="Default.html" mce_href="Default.html">主頁</a>
    <br />
    <br />
    <a href ="List_p1.html">List頁傳page參數(shù)</a>
    <br />
    <br />
    <a href ="Detial_1.html">Detial頁傳值Id參數(shù)</a>
        <br />
    <br />
    <a href ="About_jianjie.html">About頁傳值title參數(shù)</a>
       <br />
    <br />
    <a href ="Double_t1_p1.html">Double頁傳值type和page參數(shù)</a>
         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </div>
    </form>

cs代碼:

//About頁面
public partial class About : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string title = Request["title"].ToString();
        TextBox1.Text = "name為" + title;
    }
}
//Detial頁面
public partial class Detial : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string Id = Request["Id"].ToString();
        TextBox1.Text = "Id號為" + Id;
    }
}
//Double.aspx頁面
public partial class Double : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string type = Request["type"].ToString();
        string page = Request["page"].ToString();
        TextBox1.Text = "type為:" + type + "page為" + page;
    }
}
//List.aspx頁面
public partial class List : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string page = Request["page"].ToString();
        TextBox1.Text = "頁數(shù)為" + page;
    }
}

 

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多