Tutorials to .com

Tutorials to .com » Asp » Optimization » Url ReWriting sample

Url ReWriting sample

Print View , by: iSee ,Total views: 11 ,Word Count: 444 ,Date: Fri, 17 Apr 2009 Time: 5:04 PM

The components provided by Microsoft has been well compiled and does not need to write their code directly on the line:)

Web.Config settings for you:

<configuration> Section in the beginning with:



<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
</ configSections>
<configuration> Added in section:



<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> <! [CDATA [~ / news_view.aspx? Year = $ 1 & month = $ 2 ]]></ SendTo>
</ RewriterRule>
</ Rules>
</ RewriterConfig>

In section <system.web> add:



<httpModules>
<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
</ httpModules>
To deal with some links:

news.aspx


private void Page_Load (object sender, System.EventArgs e)
(
/ / Put user code here to initialize the page
DataTable dt = new DataProvider (). GetNewsToIndexPage (1);
/ / Formatted URL
UrlFormat formats = new UrlFormat ();

lbNews.Text = "<ul>";
if (dt.Rows.Count> 0)
(
int counter = 0;
while (counter <dt.Rows.Count)
(
lbNews.Text + = "<li> <a href =" "+ formats.NewsUrl ((DateTime) dt.Rows [counter] [" NewsPubTime "], Convert.ToInt32 (dt.Rows [counter] [" NewsID "] )) + "" target = "_blank"> "+ dt.Rows [counter] [" NewsTitle "]. ToString () +" </ a> </ li> ";
counter + +;
)
)
else
(
lbNews.Text = "<li style="color:red"> temporary No </ li>";
)
lbNews.Text + = "</ ul>";
dt.Clear ();
dt.Dispose ();

)
UrlFormat.cs



public 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 virtual string GetUrl (string pattern, params object [] items)
(
return string.Format (pattern, items);
)

)


Formatted as follows:
news, 2004,8,13,123. aspx

Point:
news.aspx? parameter = some parameter


Asp Optimization Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.