相关疑难解决方法(0)

如何从Global.asax获取OwinContext?

我正在尝试设置我的依赖注入,我需要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)

c# asp.net-mvc simple-injector owin

16
推荐指数
1
解决办法
7276
查看次数

在上下文中找到了Microsoft.Owin.Host.SystemWeb并且仍然没有获得owin.Environment项

我已经阅读了很多这方面的帖子,但仍然无法使其发挥作用.我正在使用Visual Studio 2013.我创建了一个新的MVC 5项目,并认为使用新的facebook登录集成会很酷.它在我的电脑上在IIS Express中工作正常.

但是当我将它上传到生产服务器时,我不断收到非常烦人的"在上下文中找到No owin.Environment项目"消息.

这就是我所做的.

  1. 我从未改变过我的项目或装配的名称.
  2. 程序集名称为Wodivate
  3. 命名空间是Wodivate
  4. 我有默认的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)
  5. 在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)

c# owin visual-studio-2013

9
推荐指数
1
解决办法
1万
查看次数

ASP.NET MVC:没有owin.Environment

我觉得我遇到了与此主题中描述的问题相同的问题.我正在开发一个在本地运行良好的ASP.NET MVC Web应用程序.但是,当使用IIS7部署到我们的Windows Server 2008时,尝试登录时出现以下错误:

在上下文中找不到owin.Environment项.

这是触发此错误的行:

return _signInManager ?? HttpContext.GetOwinContext().Get<ApplicationSignInManager>();
Run Code Online (Sandbox Code Playgroud)

我尝试了所有我能找到的东西:

  1. 添加 <add key="owin:AppStartup" value="My_App.Startup,My-App"/>web.config脚趾.我的应用程序在其名称中有一个连字符,但这应该不是问题,对吧?
  2. 添加<add key="owin:AutomaticAppStartup" value="true"/>到web.config.
  3. 添加<modules runAllManagedModulesForAllRequests="true">到web.config.
  4. 我确认Microsoft.Owin.Host.SystemWeb已安装并在bin文件夹中.
  5. 清除ASP.net临时文件.
  6. 应用程序池设置为"集成"

它在当地工作得很好.我错过了什么?

这不是主题的重复.我从那里尝试过解决方案(参见我的#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)

c# asp.net iis

7
推荐指数
1
解决办法
1526
查看次数