URL REWRITING example (C #)

xiaoxiao2021-03-06  94

Set up to Web.config:

in

The festival starts with:

<

Configsections

>

<

section

Name

= "RewriterConfig"

Type

= "Urlrewriter.config.rewriterconfigserializersECTIONHANDLER, URLREWRITER"

/>

CONFIGSECTIONS>

in

Plus:

<

RewriterConfig

>

<

Rules

>

<

Rewriterrule

>

<

Lookfor

>

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

Lookfor> ~ / news_view.aspx? Newsid = $ 4

Sendto>

ReWriterrule> ~ / (D {4}) / (D {2}) / Default.aspx

LOOKFOR> ~ / news_view.aspx? Year = $ 1 & month = $ 2]]> sendto> rules> rules> REWRITERCONFIG>

In addition:

httpmodules>

Treat a link: news.aspx

Private void page_load (object sender, system.eventargs e) {// Place user code here to initialize 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 "]. Tostring () "; counter ;}} else {lbnews.text = "No content";} lbnews.text = "; dt.clear (); DT .Dispose ();

URLFORMAT.CSPUBLIC CLASS URLFORMAT {Public UrlFormat () {} Public Virtual String NewsURL (DateTime DT, INT NEWSID) {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

Role: You can hide the true URL, cool!

Related DLL file download: http://bbs.mvpcn.net/postattachment.aspx? Postid = 405

Another one: http://www.codeproject.com/aspnet/urlrewriter.asp]>

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

New Post(0)