URL REWRITING example

xiaoxiao2021-03-06  133

This component provided by Microsoft has been compiled, no need to write code, use it directly :) For web.config: In , start with:

<

Configsections

>

<

section

Name

= "RewriterConfig"

Type

= "Urlrewriter.config.rewriterconfigserializersECTIONHANDLER, URLREWRITER"

/>

Configsections

>

Plus in :

<

RewriterConfig

>

<

Rules

>

<

Rewriterrule

>

<

Lookfor

>

~ / News, (D {4}), (D {1, 2}), (D {1, 2}), (D {1, 9}). ASPX

Lookfor

>

<

Sendto

>

~ / news_view.aspx?

Newsid = $ 4

Sendto

>

Rewriterrule

>

<

Rewriterrule

>

<

Lookfor

>

~ / (d {4}) / (d {2}) / default.aspx

Lookfor

>

<

Sendto

>

~ / news_view.aspx? Year = $ 1 & Month = $ 2

]]]]

Sendto

>

Rewriterrule

>

Rules

>

RewriterConfig

>

Plus: add:

<

Httpmodules

>

<

Add

Type

= "Urlrewriter.ModuleRewriter, urlrewriter"

Name

= "ModuleWriter"

/>

Httpmodules

>

Treat a link: news.aspx

Private

Void

Page_load

Object

Sender, System.EventArgs E)

{// Place the user code here to initialize the page DATATABLE DT = New DataProvider (). GetnewstoIndexpage (1); // Format URL URLFORMAT FORMATS = New urlFormat (); lbnews.text = "

    "; if Dt.Rows.count> 0) {int counter = 0; while (counter Dt.Rows [counter] [" newstitle "]. } Else {lbnews.text} else {lbnews.text} else {lbnews.text} else {lbnews.text = "
  • No content ";} lbnews.text = ""; dt.clear (); dt.dispose ();} urlformat.cs

    public

    Class

    UrlFormat

    {Public urlformat () {} public virtual string newsurl (DateTime DT, INT news) {Return geturl ("news, {0}, {1}, {2}," newsid ".aspx", dt.year, DT.MONTH, DT.DAY);} protected pattern, params object [] items) {return string.format (pattern, items);}}

    Formatted as: News, 2004, 8, 13, 123.aspx pointing: news.aspx? Parameters = Some parameter effect: You can hide the true URL, cool! Related DLL file download: http://bbs.mvpcn.net/postattachment.aspx? Postid = 405

转载请注明原文地址:https://www.9cbs.com/read-127443.html

New Post(0)