为 IIS 配置联合被动信赖方 7 经典模式错误(无法执行 URL)



我有一个 ASP.Net 信赖方,它使用Microsoft标识模型和 WIF 作为被动联合标识。Web 应用程序在 .Net 4 集成管道应用程序池下的 IIS 7 中工作正常。但是,当我将其切换到 .Net 4 经典管道应用程序池时,它会失败并出现以下错误。如何解决这个问题?

异常详细信息:System.Web.HttpException:无法执行 URL。

堆栈跟踪:

[httpException (0x80004005):无法执行 URL。 System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6.BeginExecuteUrl(String url, String method, String childHeaders, Boolean sendHeaders, Boolean addUserIndo, IntPtr token, String name, String authType, Byte[] entity, AsyncCallback cb, Object state) +4040320 System.Web.HttpResponse.BeginExecuteUrlForEntireResponse(String pathOverride, NameValueCollection requestHeaders, AsyncCallback cb, Object state) +590 System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state) +286 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +405 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completeSyncally) +375

编辑

当我浏览到网站而未指定页面时,会发生此错误。例:

1 - http://www.relyingparty3.com 导致错误

2 - http://www.relyingparty3.com/Default.aspx 工作正常

我在以下MSDN论坛线程中找到了一个解决方案。功劳归于用户"paullem"(解释失败的原因)和"Alex Stankiewicz"(使修复代码可用):

http://social.msdn.microsoft.com/Forums/en/Geneva/thread/43392dc5-e764-4027-8de5-1638a4c17540

因此,为了解决这个问题,我使用以下代码创建了一个新类:

using System;
using System.Web;
using System.Security.Principal;
using System.Threading;
using Microsoft.IdentityModel.Claims;
using Microsoft.IdentityModel.Web;
namespace TestApp.Code
{
    public class IIS6SessionAuthenticationModule : SessionAuthenticationModule
    {
        protected override void OnPostAuthenticateRequest(object sender, EventArgs e)
        {
            if (!(HttpContext.Current.User is IClaimsPrincipal))
            {
                IClaimsPrincipal incomingPrincipal = ClaimsPrincipal.CreateFromHttpContext(HttpContext.Current);
                ClaimsAuthenticationManager manager = base.ServiceConfiguration.ClaimsAuthenticationManager;
                if (((manager != null) && (incomingPrincipal != null)) && (incomingPrincipal.Identity != null))
                {
                    incomingPrincipal = manager.Authenticate(HttpContext.Current.Request.Url.AbsoluteUri, incomingPrincipal);
                }
                if (incomingPrincipal.Identity.IsAuthenticated)
                {
                    HttpContext.Current.User = incomingPrincipal;
                    Thread.CurrentPrincipal = incomingPrincipal;
                }
                else
                {
                    HttpContext.Current.User = new GenericPrincipal(new GenericIdentity(string.Empty), new string[] { });
                    Thread.CurrentPrincipal = HttpContext.Current.User;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(HttpContext.Current.User.Identity.Name))
                {
                    HttpContext.Current.User = new GenericPrincipal(new GenericIdentity(string.Empty), new string[] { });
                    Thread.CurrentPrincipal = HttpContext.Current.User;
                }
            }
        }
    }
}

然后,我在"web.config"中"system.web"的"httpModules"中添加了以下条目,在"WSFederationAuthenticationModule"和"SessionAuthenticationModule"之后:

<add name="IIS6SessionAuthenticationModule" type="TestApp.Code.IIS6SessionAuthenticationModule, TestApp" />

尾部斜杠存在问题。

如果键入:http://www.relyingparty3.com/,会发生什么情况

(注意尾部斜杠)

最新更新