Securing the rss feed with username and password,f

2019-06-07 12:58发布

问题:

How can i secure the Rss feed for private viewing?

回答1:

You can secure the feed the same way you would any other file, via the web.config. Something along the lines of:

<configuration>
  <system.web>
    <authentication mode="Forms">
      <forms name=".AUTH" loginUrl="login.aspx" protection="All" timeout="60">
        <credentials passwordFormat="MD5">
          <user name="admin" password="" />
        </credentials>
      </forms>
    </authentication>
    <authorization>
      <allow users="?" />
      <allow users="*" />
    </authorization>
  </system.web>

  <location path="feed.xml">
    <system.web>
      <authorization>
        <allow users="admin" />
        <deny users="*" />
      </authorization> 
    </system.web>
  </location>
</configuration>


回答2:

If you have controller action and use builtin authorization then decorate action result with [Authorize] attribute:

[Authorize (Users="List of users", Roles="List of roles")]
RssActionResult RssFeed(params)
{
}