我试图在现有应用程序中实现 OWIN WS Federation。它是一个使用 asp .net VB 编写的 Web 应用程序。
我已经添加了 Nugetpackages 中的所有引用添加的参考文献列表
然后我将启动类添加到 2 个文件中作为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
和 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 出错
问题是您没有提供该人的全名Startup类,包括其名称空间。即使您在类文件中不使用命名空间,也已经配置了默认的全局命名空间。
默认命名空间在您的项目设置中定义为根命名空间。它与您的项目名称相同。检查您的项目属性。它将在根命名空间 field.
现在如果你的项目被称为一些项目您可以使用以下选项之一进行配置:
- 使用属性:
<Assembly: OwinStartupAttribute(GetType(SomeProject.Startup))>
(同时删除owin:AppStartup
键入您的 web.config 文件)
- 使用 web.config 键:
<add key="owin:AppStartup" value="SomeProject.Startup" />
请注意我如何删除“.vb”部分,因为密钥需要完整的类名而不是文件名。
使用 web.config 会覆盖属性中的值。因此,在您的情况下,您只需要使用其中之一,而不需要同时使用两者。
你可以检查微软的文档更好地了解 OWIN 如何检测Startup class.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)