我正在尝试设置我的依赖注入,我需要IAuthenticationManager从ASP.NET身份注入一个OwinContext.
为此,我来自我的Global.asax -> ServiceConfig.Configure()跑步:
container.Register(() => HttpContext.Current.GetOwinContext().Authentication);
Run Code Online (Sandbox Code Playgroud)
但是,当我运行我的应用程序时,我收到此消息:
在上下文中找不到owin.Environment项
为什么这个HttpContext.Current.GetOwinContext()不能从Global.asax获得?
Startup.cs
[assembly: OwinStartupAttribute(typeof(MyApp.Web.Startup))]
namespace Speedop.Web
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
}
}
Run Code Online (Sandbox Code Playgroud)
Startup.Auth.cs
public partial class Startup
{
public void ConfigureAuth(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<UserManager<User, int>, User, int>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentityCallback: (manager, user) => manager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie),
getUserIdCallback: (id) => (Int32.Parse(id.GetUserId())) …Run Code Online (Sandbox Code Playgroud) 我已经阅读了很多这方面的帖子,但仍然无法使其发挥作用.我正在使用Visual Studio 2013.我创建了一个新的MVC 5项目,并认为使用新的facebook登录集成会很酷.它在我的电脑上在IIS Express中工作正常.
但是当我将它上传到生产服务器时,我不断收到非常烦人的"在上下文中找到No owin.Environment项目"消息.
这就是我所做的.
我有默认的Startup.cs类,其中包含以下内容:
using Microsoft.AspNet.Identity;
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Owin;
using System.Web.Http;
[assembly: OwinStartupAttribute(typeof(Wodivate.Startup))]
namespace Wodivate
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
}
}
Run Code Online (Sandbox Code Playgroud)在App_Start中有一个Startup.Auth.cs文件,其中包含:
using Microsoft.AspNet.Identity;
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Owin;
namespace Wodivate
{
public partial class Startup
{
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
// Enable the application to use a …Run Code Online (Sandbox Code Playgroud)我觉得我遇到了与此主题中描述的问题相同的问题.我正在开发一个在本地运行良好的ASP.NET MVC Web应用程序.但是,当使用IIS7部署到我们的Windows Server 2008时,尝试登录时出现以下错误:
在上下文中找不到owin.Environment项.
这是触发此错误的行:
return _signInManager ?? HttpContext.GetOwinContext().Get<ApplicationSignInManager>();
Run Code Online (Sandbox Code Playgroud)
我尝试了所有我能找到的东西:
<add key="owin:AppStartup" value="My_App.Startup,My-App"/>web.config脚趾.我的应用程序在其名称中有一个连字符,但这应该不是问题,对吧?<add key="owin:AutomaticAppStartup" value="true"/>到web.config.<modules runAllManagedModulesForAllRequests="true">到web.config.Microsoft.Owin.Host.SystemWeb已安装并在bin文件夹中.它在当地工作得很好.我错过了什么?
这不是此主题的重复.我从那里尝试过解决方案(参见我的#1)但没有成功.另外,我还没有更改名称空间.
编辑 一个解决方案是在web.config中显式注册OwinHttpHandler但这有一些奇怪的副作用(我的CSS和JavaScript不再加载,状态404?):
<handlers>
<add name="OWIN" path="*" verb="*" type="Microsoft.Owin.Host.SystemWeb.OwinHttpHandler" />
</handlers>
Run Code Online (Sandbox Code Playgroud)