标签: owin

OWIN 服务器中的错误响应、启动选项

我的 OWIN selfhost 服务器出现一些问题。我正在尝试使其可以通过我的本地网络进行访问。这意味着主机的 IP 地址将用于连接到服务器。糟糕的是,我收到了错误的请求,主机名无效。

我做了一些谷歌搜索,找到了有关启动选项的可能解决方案:

StartOptions options = new StartOptions();
options.Urls.Add("http://localhost:9095");
options.Urls.Add("http://127.0.0.1:9095");
options.Urls.Add(string.Format("http://{0}:9095", Environment.MachineName));
Run Code Online (Sandbox Code Playgroud)

现在我尝试实现它却出现错误:

static void Main()
        {
            string baseAddress = "http://localhost:4004/";

            /*Render application
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FrontVorm());
            */
            // Start OWIN host 
            StartOptions options = new StartOptions();
            options.Urls.Add("http://localhost:4004");
            options.Urls.Add("http://127.0.0.1:4004");
            options.Urls.Add(string.Format("http://{0}:4004", Environment.MachineName));
            using (WebApp.Start<Program>(options))
            {

                // Create HttpCient and make a request to api/values 
                HttpClient client = new HttpClient();
            }
}
Run Code Online (Sandbox Code Playgroud)

我最初使用 baseURL 来完成此操作,然后使用我的启动程序 (url : baseAdress) 来完成此操作。但现在我收到错误并且我的服务器停止运行。

{"The following errors occurred while attempting to load the …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-web-api owin

2
推荐指数
1
解决办法
2082
查看次数

使用两个 URL 使用 Azure AD 进行单点登录

假设我有 2 个 url 指向一个网站,只需使用站点绑定,例如:

productname1.company.com
productname2.company.com
Run Code Online (Sandbox Code Playgroud)

我们的 Web 应用程序单点登录到 Azure Active Directory,并且在 Azure 应用程序配置中,我放置了:

productname1.company.com
Run Code Online (Sandbox Code Playgroud)

对于登录 URL 和回复 URL:

在此输入图像描述

如果用户来到productname1.company.com,Azure 单点登录身份验证工作正常。

但如果用户来了productname2.company.com,它根本不起作用并重定向到 的登录页面productname1.company.com

如何配置才能使其与productname2.company.comAzure AD 一起使用,我正在使用 OWIN OpenIdConnect 进行单点登录。

asp.net-mvc single-sign-on owin azure-active-directory openid-connect

2
推荐指数
1
解决办法
1797
查看次数

swagger ui 中的 OData 查询

我正在查看以下教程:http://blogs.msdn.com/b/martinearn/archive/2015/03/10/using-odata-query-syntax-with-web-api.aspx

我很好奇 swagger ui 是否支持以某种方式显示查询参数。

本质上,我希望所有用 [EnableQueryAttribute] 属性标记的调用都具有用于输入查询参数的 swagger ui,并且我不想将这些参数添加到方法调用中,我仍然希望它们位于 URL 中并为 Owin 上下文拉出。

有什么建议么?

c# odata owin swagger-ui swagger-2.0

2
推荐指数
2
解决办法
5218
查看次数

Asp.Net Web API oAuth 2.0 无法使用包含与号 (&amp;) 的密码进行验证

我的 AngularJs 应用程序遇到有线问题。当用户尝试登录应用程序时,如果密码包含与号 (&),则无法验证用户。

我正在使用 OWIN、oAuth2.0 JWT 令牌来验证我的 Asp.Net Web API。

当我调试时,我发现如果密码包含与号(&),那么它会截断与号(&)中的所有字符。

例如,如果密码是“x&x”,则 OAuthValidateClientAuthenticationContext 上下文在密码值中仅获取“x”。

我已附上该问题的屏幕截图,单击即可查看该问题。

对于这个问题的任何帮助,我们将不胜感激。

asp.net oauth jwt asp.net-web-api owin

2
推荐指数
1
解决办法
1438
查看次数

来自谷歌控制台的动态重定向 url - oAuth

我创建了一个 MVC/API 项目来启用外部身份验证,并且对我的本地主机 url 工作正常。但是,我需要实现以下目标。

  1. 我支持多租户(相同的应用程序服务和不同的数据库),因此每个租户必须根据 MVC url 中的自定义参数连接不同的数据库,例如:https://localhost/tenant1 , .../tenant2, ... /tenant3 等(此时不使用单独的子域)

  2. 我不确定 Google 控制台是否支持通配符 url 作为返回 ur 并且不确定如何在 MVC 代码中实现它(例如:http://localhost/ * OR {0} .. 类似的东西。(所以动态输入参数将从谷歌返回)

我正在阅读并尝试一些解决方案。一旦我得到完整的解决方案,将在这里更新答案。同时,如果有人有任何建议,请帮助我。

更新1:

我已更新我的源代码如下:

在重定向到外部登录之前创建会话对象

System.Web.HttpContext.Current.Session["Tenant"] = "tenantname";
Run Code Online (Sandbox Code Playgroud)

回调后读取租户详细信息并保存在会话中,以根据租户名称进行后续的数据库调用

public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
    {
        var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
        if (loginInfo == null)
        {
            return RedirectToAction("Login");
        }

        if (System.Web.HttpContext.Current.Session["Tenant"] != null)
        {
            string sessionObj = System.Web.HttpContext.Current.Session["Tenant"] as String;
        }
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc google-api multi-tenant google-oauth owin

2
推荐指数
1
解决办法
1458
查看次数

ASP.NET PhysicalFileProvider 在 Startup.cs 中不可用

我正在尝试使用实体框架在 ASP.NET 4.6 Web 应用程序 MVC 5.2.3 中提供静态文件。我正在关注教程。

我收到编译器错误:

找不到类型或命名空间名称“PhysicalFileProvider”(您是否缺少 using 指令或程序集引用?)

似乎Microsoft.Extensions.FileProviders实际上并未使用 using (它在 Visual Studio 中显示为灰色。

我试过导入各种程序集,但没有任何运气。我不是 .NET 开发人员,任何帮助将不胜感激。

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Primitives;
using Microsoft.Owin;
using Microsoft.Owin.StaticFiles;
using Microsoft.Extensions.Configuration;

using Owin;

[assembly: OwinStartup(typeof(Monica.Startup))]

namespace Monica
{
    public partial class Startup
    {

        public void Configuration(IAppBuilder app)
        {
            app.UseStaticFiles(); // For the wwwroot folder

            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider = new PhysicalFileProvider(
                    Path.Combine(Directory.GetCurrentDirectory(), @"MyStaticFiles")),
                RequestPath = new PathString("/StaticFiles")
            });
        }
    } …
Run Code Online (Sandbox Code Playgroud)

c# asp.net iis nuget owin

2
推荐指数
1
解决办法
2533
查看次数

检索 Autofac 容器以解析服务

在 C# WindowForms 应用程序中,我启动了一个 OWIN WebApp,它创建了我的另一个类 Erp 的单例实例:

public partial class Engine : Form
{
    const string url = "http://*:8080"; //49396
    private IDisposable webApp;

    public Engine()
    {
        InitializeComponent();
        StartServer();
    }

    private void StartServer()
    {
        webApp = WebApp.Start<Startup>(url);
        Debug.WriteLine("Server started at " + url);
    }

    private void btnDoSomething(object sender, System.EventArgs e)
    {
       // needs to call a method in erp
    }
}

class Startup
{
    public void Configuration(IAppBuilder app)
    {
        Trace.Listeners.Remove("HostingTraceListener");
        app.UseCors(CorsOptions.AllowAll);

        var builder = new ContainerBuilder();
        var config = new …
Run Code Online (Sandbox Code Playgroud)

c# autofac owin

2
推荐指数
1
解决办法
5766
查看次数

Chrome 未在我的 OpenID Connect 工作流程 (ASP.NET OWIN) 中保存/返回 Nonce cookie

我正在尝试让 OpenID Connect 身份验证适用于我的旧版 ASP.NET MVC 应用程序。我的 ASP.NET MVC 应用程序将作为中继方,我们的业务合作伙伴将作为身份提供者。

为了熟悉我需要做什么,我在 Auth0 上创建了一个帐户,并为 Web 应用程序创建了一个新的应用程序。然后我从 GitHub 下载了他们的 ASP.NET MVC OWIN 快速入门。我已完成所有设置,并且能够使用 Microsoft Edge 和 Firefox成功进行身份验证。但对于 Chrome,工作流程是这样的:

  1. 访问本地主机:3000
  2. 尝试访问受保护的资源,这会将我重定向到 localhost:3000/Account/Login
  3. /Account/Login 创建质询,它执行两件事:(1) 创建 Nonce cookie,以及 (2) 将用户重定向到 Auth0 的/authorize端点
  4. 我在 Auth0 的登录屏幕上成功登录
  5. /callback向localhost:3000 上的端点发出 POST 请求
  6. 我收到黄屏死机并显示以下消息:

IDX21323:RequireNonce 是“System.Boolean”。OpenIdConnectProtocolValidationContext.Nonce 为 null,OpenIdConnectProtocol.ValidatedIdToken.Payload.Nonce 不为 null。无法验证随机数。如果不需要检查随机数,请将 OpenIdConnectProtocolValidator.RequireNonce 设置为“false”。请注意,如果找到“随机数”,则会对其进行评估。

检查 HTTP 流量,我发现Chrome 的问题在于步骤 (3) 中 - 当服务器在 302 重定向中设置 Nonce cookie 时 - Chrome 没有保存它。因此,当步骤(5)发生时,浏览器不会向服务器发送任何Nonce信息,验证失败。 …

cookies asp.net-mvc owin openid-connect auth0

2
推荐指数
1
解决办法
6164
查看次数

MVC从响应中删除ApplicationCookie

在之前使用表单身份验证的MVC项目中,我能够使用具有以下覆盖的动作过滤器从响应中剥离身份验证cookie.

public override void OnResultExecuted(ResultExecutedContext filterContext)
{
    filterContext.HttpContext.Response.Cookies.Remove(FormsAuthentication.FormsCookieName);
}
Run Code Online (Sandbox Code Playgroud)

我现在已经切换到使用基于OWIN的asp.net身份2.0,并且我想以同样的方式删除他们的身份验证cookie版本.

我修改了过滤器(下面)以使用新的cookie名称,但不再删除cookie.

public override void OnResultExecuted(ResultExecutedContext filterContext)
{
    const string authenticationCookie = CookieAuthenticationDefaults.CookiePrefix + DefaultAuthenticationTypes.ApplicationCookie;
    filterContext.HttpContext.Response.Cookies.Remove(authenticationCookie);
}
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么?

authentication cookies asp.net-mvc owin asp.net-identity

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

Owin WebApi 2主机名IntegratedAuth失败 - 400错误和错误的凭据

我有一个使用OWIN自托管的Intranet应用程序来提供SPA/WebAPI 2类型的站点.一切都很好,如localhost:port和IP:port,但是IE和Chrome的主机名:端口都失败了.然而,该应用程序适用于FireFox.

我相信这是由于集成身份验证.Chrome返回ERR_INVALID_AUTH_CREDENTIALS,IE返回400错误请求.Fiddler在请求/响应的标头中没有显示出太大差异,除了身份验证通过,我得到一个200的FF,一个400的IE和一个401的Chrome.

我的大多数代码都是从SO文章或MSDN教程中"借用"的.这是我的Program.cs:

string baseAddress = "http://*:9000/";
using (WebApp.Start<Startup>(new StartOptions(baseAddress) { ServerFactory =  "Microsoft.Owin.Host.HttpListener" }))
{
    // Keep server operational till stopped
    Console.WriteLine("Started, Press any key to stop.");
    Console.ReadKey();
    Console.WriteLine("Stopped");
 }
Run Code Online (Sandbox Code Playgroud)

这是我的startup.cs:

public void Configuration(IAppBuilder appBuilder)
{
    var listener = (HttpListener)appBuilder.Properties["System.Net.HttpListener"];
    listener.AuthenticationSchemes = AuthenticationSchemes.IntegratedWindowsAuthentication;

    // Configure Web API for self-host. 
    HttpConfiguration config = new HttpConfiguration();

    WebApiConfig.Register(config);
    appBuilder.UseWebApi(config);
    appBuilder.UseFileServer(new FileServerOptions
    {
        RequestPath = new PathString(string.Empty),
        //  path to static files.
        FileSystem = new PhysicalFileSystem("./public"),
        EnableDirectoryBrowsing = false
    });
}
Run Code Online (Sandbox Code Playgroud)

我还确保使用netsh设置网址预留: …

c# authentication httplistener asp.net-web-api owin

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