未检测到OWIN启动类 [英] OWIN Startup class not detected

查看:109
本文介绍了未检测到OWIN启动类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I was trying to implement OWIN WS Federation in an existing application. It's a web application in asp .net VB. I have added all the references from the Nugetpackages List of refernces added

然后我将启动类添加为2个文件作为Partial类.

Then I added the startup class in 2 files as a Partial class.

StartupAuth.vb:

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:

and 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中添加了这两行:

I also added these two lines in the webconfig:

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

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

If anyone has any idea about what is happening please let me know.

提前谢谢.

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

As I dont have a namespace for the project and the startup files I have not added it in the config file. When I try to run the application I get the following error:

运行应用程序时Chrome错误

推荐答案

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

The problem is that you are not providing the full name of the Startup class including its namespace. Even if you don't use a namespace in your class files there is a default global one already configured.

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

The default namespace is defined in your project settings as Root namespace. It is the same as your project name. Check your project properties. It will be in the Root namespace field.

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

Now if your project is called SomeProject you could configure using one of these options:

  1. 使用属性:<Assembly: OwinStartupAttribute(GetType(SomeProject.Startup))> (还删除您的web.config文件中的owin:AppStartup键)
  2. 使用web.config密钥:<add key="owin:AppStartup" value="SomeProject.Startup" />
  1. Using the attribute: <Assembly: OwinStartupAttribute(GetType(SomeProject.Startup))> (Also remove the owin:AppStartup key in your web.config file)
  2. Using the web.config key: <add key="owin:AppStartup" value="SomeProject.Startup" />

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

Note how I removed the ".vb" part as the key expects a full class name and not a file name.

使用web.config会覆盖Attribute中的值.因此,在您的情况下,您只需要使用其中之一即可.

Using the web.config overrides the value in the Attribute. So you only need to use one of them and not both in your case.

您可以检查

you can check Microsoft's documentation to better understand how OWIN detects the Startup class.

这篇关于未检测到OWIN启动类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆