2017-07-27 3 views
0

Mon application Web ASP.NET utilise un Windows Authentication et je veux juste permettre aux utilisateurs anonymous d'entrer un dossier (appelons-le "XYZ"). Ainsi, dans le XYZ j'ai une configuration web créé par IIS:IIS 10.0 - AllowAnonymous pour un dossier d'application (le contrôleur ne fonctionne pas)

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
     <security> 
      <authentication> 
       <windowsAuthentication enabled="false" /> 
      </authentication> 
     </security> 
    </system.webServer> 
</configuration> 

A l'intérieur du XYZ J'ai une page HTML, et entrez l'URL comme:

www.site.com/XYZ/htmlPage.html 

Il ouvre sans poser des questions sur autorisations et tout est bon. Mais quand je fais la même chose avec mon action de contrôleur (le contrôleur est à l'intérieur du XYZ de couse), je reçois le code d'erreur 401.

Controller:

[AllowAnonymous] 
public class TestController : Controller 
{ 
    [AllowAnonymous] 
    public ActionResult Index() 
    { 
     return Content("Test content"); 
    } 
} 

Routing:

 routes.MapRoute(
      name: "XYZRoute", 
      url: "XYZ/{controller}/{action}/{id}", 
      defaults: new { controller = "Test", action = "Index", id = UrlParameter.Optional }); 

Aucune idée où je fais une erreur

Répondre

1

Vous pouvez ajouter dans votre principale web.config à l'intérieur <configuration> section:

<location path="XYZ"> 
    <system.webServer> 
    <security> 
     <authentication> 
      <windowsAuthentication enabled="false" /> 
     </authentication> 
    </security> 
</system.webServer> 
</location> 

Et vous pouvez supprimer supprimer la configuration Web à l'intérieur XYZ dossier