gpt4 book ai didi

Owin 托管的 NancyFX 应用程序在发布到 IIS 后返回无法加载类型 Nancy.Hosting.Aspnet.NancyHttpRequestHandler

转载 作者:行者123 更新时间:2023-12-02 05:42:29 24 4
gpt4 key购买 nike

虽然通过 VS Studio 附带的 IIS Express 在本地运行时它可以完美运行,但我的应用程序一旦部署到 IIS 8 就会卡住:

System.Web.HttpException: Could not load type 'Nancy.Hosting.Aspnet.NancyHttpRequestHandler'.

后端是 MS Owin,用 VB (.NET 4.5) 编写,注册了 3 个中间件:OAuth 服务器、JWT 承载身份验证和 Nancy。前端是AngularJS。正确的 DLL 包含在已发布的目录中。

IIS 8 安装并启用了 .NET 4.5。它正在集成模式下运行。

我不确定这是否与web.config中Nancy的配置或IIS的配置有关。相关来源如下:

启动.vb

Public Sub Configuration(app As IAppBuilder)

Dim issuer As String = "http://obscured-domain"
Dim audience As String = "obscured-audience-key"
Dim secret As Byte() = Microsoft.Owin.Security.DataHandler.Encoder.TextEncodings.Base64Url.Decode("obscured-client-secret")

'CORS Configuration
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll)
app.UseOAuthAuthorizationServer(New OAuthAuthorizationServerOptions() With { _
.AllowInsecureHttp = True, _
.TokenEndpointPath = New PathString("/authenticate"), _
.AccessTokenExpireTimeSpan = TimeSpan.FromHours(1), _
.AccessTokenFormat = New JwtFormat(issuer, audience), _
.Provider = New OAuthServerProvider()
})
app.UseJwtBearerAuthentication(New JwtBearerAuthenticationOptions() With { _
.AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active, _
.AllowedAudiences = New String() {audience}, _
.IssuerSecurityTokenProviders = New IIssuerSecurityTokenProvider() { _
New SymmetricKeyIssuerSecurityTokenProvider(issuer, secret)
}
})
'Content service
Dim nOpts As New NancyOptions
nOpts.PassThroughWhenStatusCodesAre(HttpStatusCode.NotFound, HttpStatusCode.InternalServerError)
app.UseNancy(nOpts)
'Handle IIS request pipeline staging
app.UseStageMarker(PipelineStage.MapHandler)
End Sub

Web.config

    <?xml version="1.0"?>
<configuration>
<system.web>
<customErrors mode="Off" />
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<httpHandlers>
<add verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*" />
</httpHandlers>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="Nancy" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*"/>
</handlers>
</system.webServer>
<connectionStrings>
<add name="FTConnStr" connectionString="obscured-connection-string" />
</connectionStrings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

Nancy 模块示例

Public Class KnowledgeBaseModule
Inherits NancyModule

'Get page of article briefs via full-text search
MyBase.Get("/api/articles/paged/{offset}/{numRows}") = _
Function(parameters)
Dim searchFields As FullTextFields = Me.Bind(Of FullTextFields)()
Try
Dim results As Dictionary(Of String, List(Of Dictionary(Of String, Object)))
results = FullTextProvider.pagedSearch(searchFields.fields("SearchString"), CInt(parameters.offset), CInt(parameters.numRows))
Return Response.AsJson(results)
Catch ex As Exception
'temp 500
Return HttpStatusCode.InternalServerError
End Try
End Function

Private Class FullTextFields
Public Property fields As Dictionary(Of String, String) = New Dictionary(Of String, String) From _
{
{"SearchString", String.Empty}
}
End Class
End Class

最佳答案

由于您使用的是 OWIN,因此您需要使用 SystemWeb host不是南希的AspNet host 。您还需要从 web.config 中删除这两部分:

<httpHandlers>
<add verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*" />
</httpHandlers>

<handlers>
<add name="Nancy" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*"/>
</handlers>

您的 bin 文件夹中可能有 nancy 主机的副本,这就是它在本地工作但在部署时不起作用的原因。

关于Owin 托管的 NancyFX 应用程序在发布到 IIS 后返回无法加载类型 Nancy.Hosting.Aspnet.NancyHttpRequestHandler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28286990/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com