OWIN Startup class not detected

半世苍凉 提交于 2020-04-30 08:46:18

问题


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

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

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

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

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.

thanks in advance.

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 error while running the application


回答1:


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.

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.

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

  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" />

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

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.



来源:https://stackoverflow.com/questions/60785635/owin-startup-class-not-detected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!