簡體   English   中英

以編程方式為特定的asp.net文件設置IIS身份驗證模型

[英]Programmatically set IIS Authentication model for a specific asp.net file

我需要在IIS Web服務應用程序中設置特定asp.net文件的身份驗證模型。 主題“如何在.NET Web服務上的IIS中以編程方式設置集成Windows身份驗證?” 基本上可以滿足我的要求,但是對於整個網站而言。 除了一個我的Web服務,我需要具有所有匿名訪問權限,但是一個人需要使用“ Windows身份驗證”

像這樣:

在此處輸入圖片說明

應用此代碼時,我不知道如何指定某個文件:

String applicationPath = String.Format("{0}/{1}", _server.Sites["Default Web Site"].Name, "AppName"); 

Configuration config = _server.GetApplicationHostConfiguration(); 

ConfigurationSection anonymousAuthenticationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", applicationPath); 

anonymousAuthenticationSection["enabled"] = false; 

ConfigurationSection windowsAuthenticationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", applicationPath); 

windowsAuthenticationSection["enabled"] = true; 

_server.CommitChanges(); 

您可以使用web.config文件的location節點來配置應用程序的特定目錄/文件。 或者,如果您不想使根web.config混亂,則可以在子目錄中創建其他web.config文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM