How do I allow all users access to one route within a website with integrated auth?

廉价感情. 提交于 2019-11-29 13:28:20
Rebecca

In ASP.NET MVC you should not use the location element in the web.config. Whereas the web forms engine mapped to physical files on disk, the MVC engine using routing. This means that you could inadvertently allow access to a "protected controller" through a custom route by accident.

The recommended way of securing ASP.NET MVC applications is through the use of the Authorize attribute, as seen in the example below:

public class HomeController : Controller
{
    [Authorize]
    public ActionResult Index()
    { 
        return View();
    }
}

The controller action is what you want to protect and not the route. The ASP.NET MVC Security bod, Levi Broderick is rather vocal about this issue:

  1. Excluding an action from authorization in ASP.NET MVC 2
  2. Problem with Authorization with IIS and MVC.
David Gardiner

You need to allow anonymous access in IIS as well, as otherwise only windows authenticated users will be able to access anywhere in your site. You should deny access by default to anonymous users.

<deny users="?"/>
<allow users="*"/>

In your <location> section, allow anonymous users.

<allow users="?"/>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!