我的 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) 假设我有 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
我正在查看以下教程: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 上下文拉出。
有什么建议么?
我的 AngularJs 应用程序遇到有线问题。当用户尝试登录应用程序时,如果密码包含与号 (&),则无法验证用户。
我正在使用 OWIN、oAuth2.0 JWT 令牌来验证我的 Asp.Net Web API。
当我调试时,我发现如果密码包含与号(&),那么它会截断与号(&)中的所有字符。
例如,如果密码是“x&x”,则 OAuthValidateClientAuthenticationContext 上下文在密码值中仅获取“x”。
我已附上该问题的屏幕截图,单击即可查看该问题。。
对于这个问题的任何帮助,我们将不胜感激。
我创建了一个 MVC/API 项目来启用外部身份验证,并且对我的本地主机 url 工作正常。但是,我需要实现以下目标。
我支持多租户(相同的应用程序服务和不同的数据库),因此每个租户必须根据 MVC url 中的自定义参数连接不同的数据库,例如:https://localhost/tenant1 , .../tenant2, ... /tenant3 等(此时不使用单独的子域)
我不确定 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 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# 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) 我正在尝试让 OpenID Connect 身份验证适用于我的旧版 ASP.NET MVC 应用程序。我的 ASP.NET MVC 应用程序将作为中继方,我们的业务合作伙伴将作为身份提供者。
为了熟悉我需要做什么,我在 Auth0 上创建了一个帐户,并为 Web 应用程序创建了一个新的应用程序。然后我从 GitHub 下载了他们的 ASP.NET MVC OWIN 快速入门。我已完成所有设置,并且能够使用 Microsoft Edge 和 Firefox成功进行身份验证。但对于 Chrome,工作流程是这样的:
/authorize端点/callback向localhost:3000 上的端点发出 POST 请求检查 HTTP 流量,我发现Chrome 的问题在于步骤 (3) 中 - 当服务器在 302 重定向中设置 Nonce cookie 时 - Chrome 没有保存它。因此,当步骤(5)发生时,浏览器不会向服务器发送任何Nonce信息,验证失败。 …
在之前使用表单身份验证的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)
有谁知道为什么?
我有一个使用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设置网址预留: …
owin ×10
c# ×5
asp.net-mvc ×4
asp.net ×2
cookies ×2
auth0 ×1
autofac ×1
google-api ×1
google-oauth ×1
httplistener ×1
iis ×1
jwt ×1
multi-tenant ×1
nuget ×1
oauth ×1
odata ×1
swagger-2.0 ×1
swagger-ui ×1