2017-07-27 43 views
0

我的ASP.NET web應用程序使用Windows Authentication,我只想啓用anonymous用戶能夠輸入一個文件夾(我們稱之爲"XYZ")。 所以在XYZ我必須在IIS中創建一個web配置:IIS 10.0 - 一個應用程序文件夾的AllowAnonymous(控制器不起作用)

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

裏面的XYZ我有一個HTML頁面,並輸入網址,如:

www.site.com/XYZ/htmlPage.html 

它打開沒有詢問權限和一切都很好。 但是,當我對我的控制器操作(控制器在內部的XYZ內)做同樣的處理時,我得到401錯誤代碼。

控制器:

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

路由:

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

不知道在哪裏,我犯了一個錯誤

回答

1

你可以在你的主要的web.config中<configuration>部分補充一點:

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

您可以刪除XYZ文件夾中的刪除網頁配置文件

相關問題