• <legend id='Z4NEy'><style id='Z4NEy'><dir id='Z4NEy'><q id='Z4NEy'></q></dir></style></legend>
    <tfoot id='Z4NEy'></tfoot>
  • <small id='Z4NEy'></small><noframes id='Z4NEy'>

      • <bdo id='Z4NEy'></bdo><ul id='Z4NEy'></ul>
      <i id='Z4NEy'><tr id='Z4NEy'><dt id='Z4NEy'><q id='Z4NEy'><span id='Z4NEy'><b id='Z4NEy'><form id='Z4NEy'><ins id='Z4NEy'></ins><ul id='Z4NEy'></ul><sub id='Z4NEy'></sub></form><legend id='Z4NEy'></legend><bdo id='Z4NEy'><pre id='Z4NEy'><center id='Z4NEy'></center></pre></bdo></b><th id='Z4NEy'></th></span></q></dt></tr></i><div id='Z4NEy'><tfoot id='Z4NEy'></tfoot><dl id='Z4NEy'><fieldset id='Z4NEy'></fieldset></dl></div>

        在 asp.net core 1.0 中创建 RSS 提要

        时间:2023-07-10
          <tbody id='N2Q1S'></tbody>

          <i id='N2Q1S'><tr id='N2Q1S'><dt id='N2Q1S'><q id='N2Q1S'><span id='N2Q1S'><b id='N2Q1S'><form id='N2Q1S'><ins id='N2Q1S'></ins><ul id='N2Q1S'></ul><sub id='N2Q1S'></sub></form><legend id='N2Q1S'></legend><bdo id='N2Q1S'><pre id='N2Q1S'><center id='N2Q1S'></center></pre></bdo></b><th id='N2Q1S'></th></span></q></dt></tr></i><div id='N2Q1S'><tfoot id='N2Q1S'></tfoot><dl id='N2Q1S'><fieldset id='N2Q1S'></fieldset></dl></div>
            <tfoot id='N2Q1S'></tfoot>
              <bdo id='N2Q1S'></bdo><ul id='N2Q1S'></ul>

                <legend id='N2Q1S'><style id='N2Q1S'><dir id='N2Q1S'><q id='N2Q1S'></q></dir></style></legend>
                1. <small id='N2Q1S'></small><noframes id='N2Q1S'>

                  本文介绍了在 asp.net core 1.0 中创建 RSS 提要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 Asp.net Core 1.0 MVC 6我正在尝试编写一个组件来提供来自我的网站的 RSS 提要.

                  I am working in Asp.net Core 1.0 MVC 6 I am trying to write a component to provide RSS feeds from my websites.

                  我发现 这篇文章表明 System.ServiceModel.Syndication 尚未移植到 ASP.NET CORE.

                  I found this post that suggests that System.ServiceModel.Syndication has yet to be ported to ASP.NET CORE.

                  我无法针对完整的 .NET 框架.

                  I am unable to target the full .NET framework.

                  建议写成一个 xml 解析器.然而,我正在努力理解可能需要的所有内容.

                  The suggestion is to write as an xml parser. I am however struggling to get my head around everything that might be required.

                  我已经构建了将数据转换为 XML 的功能,但现在需要更好地了解如何允许从 IActionResult 调用它(或者实际上如何生成可能放置在我的页面上的链接).

                  I have built the functionality to get my data into XML but now need to better understand how to allow this to be called from an IActionResult (or indeed how to generate a link that may be placed on my page).

                  我可以提供我的代码示例,但不确定它是否有用.有人能指出我实现这一目标的正确方向吗?

                  I can provide samples of my code but am not sure it'll be helpful. Is anyone able to point me in the right direction of examples achieving this?

                  我还在这篇文章中找到了一个答案,它指向了一些想法,但我认为是 MVC6/Asp.net Core 之前的:ASP.NET MVC 中的 RSS 源

                  I also found an answer on this post which points towards some ideas but I think is pre MVC6/Asp.net Core: RSS Feeds in ASP.NET MVC

                  推荐答案

                  // action to return the feed
                  [Route("site/GetRssFeed/{type}")]
                  public IActionResult GetRssFeed(ArticleStatusTypes type)
                  {
                      var feed = _rss.BuildXmlFeed(type);
                      return Content(feed, "text/xml");
                  }
                  
                  
                  public string BuildXmlFeed(ArticleStatusTypes type)
                  {
                      var key = $"RssFeed{Convert.ToInt32(type)}{_appInfo.ApplicationId}";
                      var articles =
                              _cache.GetCachedData(key) ??
                              _cache.SetCache(key, _service.GetItems(Convert.ToInt32(type), _appInfo.CacheCount));
                  
                      StringWriter parent = new StringWriter();
                      using (XmlTextWriter writer = new XmlTextWriter(parent))
                      {
                          writer.WriteProcessingInstruction("xml-stylesheet", "title="XSL_formatting" type="text/xsl" href="/skins/default/controls/rss.xsl"");
                  
                          writer.WriteStartElement("rss");
                          writer.WriteAttributeString("version", "2.0");
                          writer.WriteAttributeString("xmlns:atom", "http://www.w3.org/2005/Atom");
                  
                          // write out 
                          writer.WriteStartElement("channel");
                  
                          // write out -level elements
                          writer.WriteElementString("title", $"{_appInfo.ApplicationName} {type}" );
                          writer.WriteElementString("link", _appInfo.WebsiteUrl);
                          //writer.WriteElementString("description", Description);
                          writer.WriteElementString("ttl", "60");
                  
                          writer.WriteStartElement("atom:link");
                          //writer.WriteAttributeString("href", Link + Request.RawUrl.ToString());
                          writer.WriteAttributeString("rel", "self");
                          writer.WriteAttributeString("type", "application/rss+xml");
                          writer.WriteEndElement();
                  
                          if (articles != null)
                          {
                              foreach (var article in articles)
                              {
                                  writer.WriteStartElement("item");
                  
                                  writer.WriteElementString("title", article.Title);
                                  writer.WriteElementString("link", _appInfo.WebsiteUrl); // todo build article path
                                  writer.WriteElementString("description", article.Summary);
                  
                                  writer.WriteEndElement();
                              }
                          }
                  
                          // write out 
                          writer.WriteEndElement();
                  
                          // write out 
                          writer.WriteEndElement();
                      }
                  
                      return parent.ToString();
                  }
                  

                  这篇关于在 asp.net core 1.0 中创建 RSS 提要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 ASP.NET MVC 6 重定向未经授权的用户 下一篇:将现有程序集添加到 mvc 6 项目

                  相关文章

                    • <bdo id='IkAHb'></bdo><ul id='IkAHb'></ul>

                    1. <i id='IkAHb'><tr id='IkAHb'><dt id='IkAHb'><q id='IkAHb'><span id='IkAHb'><b id='IkAHb'><form id='IkAHb'><ins id='IkAHb'></ins><ul id='IkAHb'></ul><sub id='IkAHb'></sub></form><legend id='IkAHb'></legend><bdo id='IkAHb'><pre id='IkAHb'><center id='IkAHb'></center></pre></bdo></b><th id='IkAHb'></th></span></q></dt></tr></i><div id='IkAHb'><tfoot id='IkAHb'></tfoot><dl id='IkAHb'><fieldset id='IkAHb'></fieldset></dl></div>

                      <small id='IkAHb'></small><noframes id='IkAHb'>

                      <legend id='IkAHb'><style id='IkAHb'><dir id='IkAHb'><q id='IkAHb'></q></dir></style></legend>
                    2. <tfoot id='IkAHb'></tfoot>