Have your website been subscribed to? (talking about rss2.0)

Source: Internet
Author: User
Has your website been subscribed to in the previous article? (About rss2.0)

Pass this articleArticleYou can understand:
1. There is a better way to create RSS
2. Create a multi-version subscription Source

Thank you herePurple permanent
This is a good tool provided by MS for US (this tool is included in the space of system. servicemodel. syndication and must be supported by. net3.x)

Next we will generate an RSS feed:
Create an Asp.net 3.5 website
Create a general application Program File (handler. ashx)
Code As follows: <% @ Webhandler Language = " C # " Class = " Handler "   %>

Myregion # Region Myregion
Using System;
Using System. collections;
Using System. Data;
Using System. LINQ;
Using System. Web;
Using System. Web. Services;
Using System. Web. Services. Protocols;
Using System. xml. LINQ;
Using System. servicemodel. Syndication;
Using System. xml;
Using System. Collections. Generic;
# Endregion


Public   Class Handler: ihttphandler {

Public   Void Processrequest (httpcontext context) {
Context. response. contenttype =   " Text/XML " ;

Prepare content items in the RSS Feed # Region Prepare content items in the RSS Feed
Syndicationitem Item1 =   New Syndicationitem ( " Blog content 1 title " , " Blog content 1 " , New Uri ( " Http://leleroyn.cnblogs.com " ));
Item1.publishdate =   New Datetimeoffset (datetime. parse ( " 12:23:24 " ));
Item1.authors. Add ( New Syndicationperson ( " Leleroyn@gmail.com " , " Ants " , String . Empty ));
Syndicationitem item2 =   New Syndicationitem ( " Blog content 2 Title " , " Blog content 2 " , New Uri ( " Http://leleroyn.cnblogs.com " ));
Item2.publishdate =   New Datetimeoffset (datetime. parse ( " 12:23:24 " ));
Item2.authors. Add ( New Syndicationperson ( " Leleroyn@gmail.com " , " Ants " , String . Empty ));
Syndicationitem item3 =   New Syndicationitem ( " Blog content 3 title " , " Blog content 3 " , New Uri ( " Http://leleroyn.cnblogs.com " ));
Item3.publishdate =   New Datetimeoffset (datetime. parse ( " 12:23:24 " ));
Item3.authors. Add ( New Syndicationperson ( " Leleroyn@gmail.com " , " Ants " , String . Empty ));
List < Syndicationitem > Items =   New List < Syndicationitem > ();
Items. Add (Item1 );
Items. Add (item2 );
Items. Add (item3 );
# Endregion

Create an RSS object # Region Create an RSS object
Syndicationfeed rs =   New Syndicationfeed ( " Ants blog " , " Blog Declaration: learn together and go up at the same time! " , New Uri ( " Http://leleroyn.cnblogs.com " ), Items );
Rs. Copyright =   New Textsyndicationcontent ( " Copyright 2008 ants " );
Rss20feedformatter rss20 = Rs. getrss20formatter (); // Create an rss2.0 Source
// Atom10feedformatter atom = Rs. getatom10formatter (); // Create atom source

# Endregion

Output Source # Region Output Source
System. Text. stringbuilder sb =   New System. Text. stringbuilder ();
Xmlwritersettings XS =   New Xmlwritersettings ();
Xs. Encoding = System. Text. encoding. utf8;
Xmlwriter XM = Xmlwriter. Create (SB, XS );
Rss1_writeto (XM );
// Atom. writeto (XM );
XM. Close ();
String Str = SB. tostring (). Replace ( " UTF-16 " , " UTF-8 " ); // Pay attention to this place, this place took me a lot of time, the default is actually UTF-16 format, dizzy
Context. response. Write (STR ); // Output to Browser
# Endregion

}
 
Public   Bool Isreusable {
Get {
Return False;
}
}

}

Just run it directly,
As for how to use this API to obtain the source, there are also corresponding methods in it. If you are interested, try it on your own. I will not demonstrate it.

If your project does not use. Net 3.x, refer to my previous article:
Have your website been subscribed? (About rss2.0)

I hope it will be helpful and I will show you ugly again.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.