3

我有一个 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& completedSynchronously) +375

编辑

当我在未指定页面的情况下浏览网站时会发生此错误。例子:

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

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

4

2 回答 2

2

我在以下 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" />
于 2012-06-06T20:56:59.343 回答
0

尾部斜杠存在问题。

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

(注意尾部斜杠)

于 2012-06-05T22:53:53.960 回答