You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 4.8 Web Forms IIS Express双虚拟目录认证配置异常求助

IIS Express中同域名下两个.NET 4.8虚拟目录的认证配置问题

我的站点在IIS中运行正常,但在IIS Express中出现异常。

核心诉求

如何在IIS Express中配置同域名下两个独立的.NET 4.8 Framework应用作为虚拟目录,分别启用Windows认证和Forms认证?目前Windows认证覆盖了两个应用的配置。

环境与流程说明

我有一个站点/域名下包含两个虚拟目录,分别指向不同应用:

- domain.com
  - virualDirectory1 (/app1windows)
  - virtualDirectory2 (/app2forms)

app1windows使用WindowsAuthentication,从Active Directory获取用户身份后创建FormsAuthentication Cookie,随后重定向到/app2forms/handler.ashx;该处理器读取Cookie并执行逻辑后,设置包含app2forms专属信息的新FormsAuthentication Cookie,此流程运行正常,我甚至将HttpContext.Current.User设置为带有FormsIdentity的新GenericPrincipal。

问题现象

问题出在/app2forms导航至页面并经过Application_AuthenticateRequest时:尽管该应用应禁用Windows认证,但HttpContext.Current.User.Identity始终为System.Security.Principal.WindowsIdentity类型。

已尝试的配置

我已在/app2forms的web.config中明确配置:

<system.web>
    <authentication mode="Forms">
        <forms cookieless="UseCookies" name="cookieName" path="/" etc. />
...

同时完成了以下操作:

  • 右键点击/app2forms项目文件,将Windows Authentication设为禁用;
  • 在其CSPROJ文件中设置<IISExpressWindowsAuthentication>disabled</IISExpressWindowsAuthentication>;
  • 打开applicationhost.config文件为每个虚拟目录设置独立的applicationPool;
  • applicationhost.config中仅app1windows明确启用了windowsAuthentication。

另外,我需要两个应用在同域名下并发运行,且web.config中设置相同的machineKey,否则跨应用Cookie无法被识别。

疑问

为何app2forms会出现WindowsIdentity?如何让一个应用识别WindowsIdentity而另一个使用FormsIdentity?

内容的提问来源于stack exchange,提问作者codeMonkey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 19:15:57