【问题标题】:IIS 8.5 Application Initialization and Windows AuthenticationIIS 8.5 应用程序初始化和 Windows 身份验证
【发布时间】:2015-01-16 06:30:26
【问题描述】:

我正在尝试使用 IIS 8.5 上的应用程序初始化模块来预热 Intranet 应用程序。设置正确并且预热工作正常,但是一旦我禁用匿名身份验证,应用程序将不再预加载(内存使用量仅为 20mb,而初始化时大约为 200mb)。

由于这些是需要身份验证的 Intranet 应用程序,因此我们传统上始终仅启用 Windows 身份验证并禁用匿名身份验证。

我正在寻找一种方法来保持此设置并进行应用程序初始化工作。 我在this page 上发现 IIS 正在使用 NT AUTHORITY\IUSR 进行请求。

在我看来,我的选择是:

  1. 启用匿名身份验证。
  2. 更改 IIS 用于发出请求的帐户。

理想情况下,我希望禁用匿名身份验证。有谁知道我如何做到这一点?

【问题讨论】:

  • 通常当您启用匿名身份验证优先级时...在您的问题缓存内存历史记录中可能是问题。解决这个尝试像这样...首先禁用匿名身份验证并启用 Windows 身份验证然后重新启动 IIS 但不是从终端从服务列表重新启动它。然后如果不重新启动机器并检查它应该重新初始化...... ********注意****我想你正在使用正确的APP Pool......

标签: iis iis-8.5


【解决方案1】:

简而言之,我建议在您的每个应用程序中允许对单个 Init.aspx 页面之类的非 SSL 匿名访问。为此,我在我的应用程序中添加了这样一个页面,其中包含文档,以帮助后续管理员/开发人员在必须将代码移动到新服务器时弄清楚如何使其工作。

reference for the web.config <applicationInitialization> tag 是一个特别帮助我弄清楚如何让它工作的参考资料。

这是我添加到我的应用程序中的 Init.aspx 页面,以防您想使用它的派生词:

<%@Page ContentType="text/plain" Language="C#" EnableSessionState="False" EnableViewState="false" AutoEventWireup="false" EnableTheming="false" StylesheetTheme="" Theme="" %>
<%--

The built-in application initialization/preload feature can help in situations where the application takes a while to 
start and/or in situations where some components of the site run as services (e.g. performing scheduled tasks).  This 
feature will make sure that the site is quick when the first user visits the site after a restart and/or will ensure that 
scheduled processes are up and running regardless of when people use the site.

Requirements/procedure for application initialization/preload:
(The procedure is slightly different in versions of IIS before 8.5 because there are no UI options.  Must instead alter
applicationHost.config.  See additional reading for more info.)

1.  Set the app pool for the application to "AlwaysRunning" :
    (IIS Manager > Application Pools > YourAppPoolHere > Advanced Settings... > Start Mode)

2.  Enable Preload: (IIS Manager > Sites> YourSiteOrAppHere > Advanced Settings... > Preload Enabled)

3.  Set initialization properties in the web.config.  e.g.:
      <applicationInitialization doAppInitAfterRestart="true">
        <add initializationPage="/PathToYourApp/Init.aspx" hostName="YourWebsiteNameHere.com" />
      </applicationInitialization>
    See this reference for more info (which can be very important):
    http://www.iis.net/configreference/system.webserver/applicationinitialization

4.  Make the Init.aspx page accessible via HTTP with Anonymous access (which may entail one or more of the following).
      - Set NTFS Permissions on the file to include the IUSR (or Everyone) security principal.
      - Adjust the Authentication, Authorization Rules, IP Address Restrictions, SSL Settings, and any other restrictions 
        for *only* the Init.aspx page:
          4.1  IIS Manager > Sites > YourSiteOrAppHere 
          4.2  Switch from 'Features View' to 'Content View' 
          4.3  Find this Init.aspx page in the right pane and highlight it 
          4.4  Switch back from 'Content View' to 'Features View' once the Init.aspx page is selected.
          4.5  You should now see Init.aspx in the tree view in the left pane.  You can now adjust the access restrictions 
               on just this page (e.g. disable SSL, enable anonymous, etc.)
               Some stuff like this might be in your config:
                 <location path="Init.aspx"><system.webServer><security><authorization>
                   <add accessType="Allow" users="?" />
                 </authorization></security></system.webServer></location>

Additional Reading:

  Some decent guides on installing and enabling Application Initialization:
  http://www.iis.net/learn/get-started/whats-new-in-iis-8/iis-80-application-initialization
  http://weblog.west-wind.com/posts/2013/Oct/02/Use-IIS-Application-Initialization-for-keeping-ASPNET-Apps-alive

  The reference for the init parameters:
  http://www.iis.net/configreference/system.webserver/applicationinitialization

-----------------------------------------------------

Note that by the time the code gets to this page, the code in your Global.asax Application_Start and/or any 
Application_Start HTTP Modules will already have fired, so you may not have any extra work to do here.  This page could 
simply be a dummy page.

TO DO: Add any extra initialization tasks outside of the comment section here if you really want to. e.g.:
<%
MyAppNameSpace.UtilityClass.DoExpensiveStartupRoutine();
%>

//.. and last, just write some dummy text if you ever want to see this page in a browser:
--%>
Application Initialized.

【讨论】:

  • 你能给出一个确切的例子来说明页面和整个站点的授权/身份验证应该是什么样的吗?我已经尝试了你的步骤,但我能够让它工作的唯一方法是为整个网站保留匿名身份验证。
  • @skeletank:很抱歉听到这个麻烦。理论上,匿名访问应该只适用于 Init.aspx 页面,就像你让它在一般网站上工作一样;您应该能够仅对 Init.aspx 文件执行对站点根目录有效的操作。要解决此问题,访问 Init.aspx 页面并查看 IIS 的“详细错误”以了解安全异常可能会有所帮助。有时异常细节会告诉你它不喜欢什么。例如。 “资源上的 ACL”是指 NTFS。 'Invalid Headers' 有时意味着授权规则等。
  • +100 为那个优秀的评论块。未来的维护者一定会爱你!
  • 感谢您的精彩评论!我要提到的另一件事是您的应用程序池必须以“集成模式”运行。自从它们从早期版本的 IIS 中引入以来,我的一直在“经典模式”下运行。应用您上面列出的所有配置后,我仍然必须将我的应用程序池从经典切换到集成。
猜你喜欢
  • 2018-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-07
  • 1970-01-01
  • 2021-04-25
  • 2016-05-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多