未检测到OWIN启动类

问题描述 投票:0回答:1

我试图在现有应用程序中实现OWIN WS Federation。这是ASP .NET VB中的Web应用程序。我已经从Nugetpackages添加了所有参考List of refernces added

然后我在2个文件中将启动类添加为Partial类。

StartupAuth.vb:

Imports System.Configuration
Imports System.Globalization
Imports System.Threading.Tasks
Imports Microsoft.Owin.Extensions
Imports Microsoft.Owin.Security
Imports Microsoft.Owin.Security.Cookies
Imports Microsoft.Owin.Security.WsFederation
Imports Owin

Partial Public Class Startup
    Private Shared realm As String = ConfigurationManager.AppSettings("ida:Wtrealm")
    Private Shared adfsMetadata As String = ConfigurationManager.AppSettings("ida:ADFSMetadata")

    Public Sub ConfigureAuth(app As IAppBuilder)
        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType)

        app.UseCookieAuthentication(New CookieAuthenticationOptions())

        app.UseWsFederationAuthentication(New WsFederationAuthenticationOptions() With {
            .Wtrealm = realm,
            .MetadataAddress = adfsMetadata
        })
        ' This makes any middleware defined above this line run before the Authorization rule is applied in web.config
        app.UseStageMarker(PipelineStage.Authenticate)
    End Sub
End Class

和Startup.vb:

Imports Microsoft.Owin
Imports Owin

<Assembly: OwinStartupAttribute(GetType(Startup))>

Partial Public Class Startup
    Public Sub Configuration(app As IAppBuilder)
        ConfigureAuth(app)
    End Sub
End Class

我还在webconfig中添加了这两行:

<add key="owin:HandleAllRequests" value="true" />
<add key="owin:AppStartup" value="Startup.vb" />

如果有人对正在发生的事情有任何想法,请告诉我。

预先感谢。

由于我没有项目和启动文件的名称空间,因此我没有将其添加到配置文件中。当我尝试运行该应用程序时,出现以下错误:

Chrome error while running the application

asp.net vb.net owin startup app-startup
1个回答
0
投票

问题是您没有提供Startup类的全名,包括其名称空间。即使您没有在类文件中使用名称空间,也已经配置了默认的全局名称空间。

默认名称空间在项目设置中定义为Root名称空间。与您的项目名称相同。检查您的项目属性。它将位于Root namespace字段中。

现在,如果您的项目名为SomeProject,则可以使用以下选项之一进行配置:

  1. 使用属性:<Assembly: OwinStartupAttribute(GetType(SomeProject.Startup))>(也删除您的web.config文件中的owin:AppStartup键)
  2. 使用web.config键:<add key="owin:AppStartup" value="SomeProject.Startup" />

请注意我是如何删除“ .vb”部分的,因为密钥需要完整的类名而不是文件名。

使用web.config会覆盖属性中的值。因此,在您的情况下,您只需要使用其中之一即可,而不必使用两者。

您可以检查Microsoft's documentation以更好地了解OWIN如何检测Startup类。

© www.soinside.com 2019 - 2024. All rights reserved.