<i id='pBFJx'><tr id='pBFJx'><dt id='pBFJx'><q id='pBFJx'><span id='pBFJx'><b id='pBFJx'><form id='pBFJx'><ins id='pBFJx'></ins><ul id='pBFJx'></ul><sub id='pBFJx'></sub></form><legend id='pBFJx'></legend><bdo id='pBFJx'><pre id='pBFJx'><center id='pBFJx'></center></pre></bdo></b><th id='pBFJx'></th></span></q></dt></tr></i><div id='pBFJx'><tfoot id='pBFJx'></tfoot><dl id='pBFJx'><fieldset id='pBFJx'></fieldset></dl></div>
    <bdo id='pBFJx'></bdo><ul id='pBFJx'></ul>
  • <small id='pBFJx'></small><noframes id='pBFJx'>

    1. <tfoot id='pBFJx'></tfoot>
      1. <legend id='pBFJx'><style id='pBFJx'><dir id='pBFJx'><q id='pBFJx'></q></dir></style></legend>

        在 Owin 启动类中指定域

        Specify Domain in Owin Startup Class(在 Owin 启动类中指定域)
      2. <i id='dKKBJ'><tr id='dKKBJ'><dt id='dKKBJ'><q id='dKKBJ'><span id='dKKBJ'><b id='dKKBJ'><form id='dKKBJ'><ins id='dKKBJ'></ins><ul id='dKKBJ'></ul><sub id='dKKBJ'></sub></form><legend id='dKKBJ'></legend><bdo id='dKKBJ'><pre id='dKKBJ'><center id='dKKBJ'></center></pre></bdo></b><th id='dKKBJ'></th></span></q></dt></tr></i><div id='dKKBJ'><tfoot id='dKKBJ'></tfoot><dl id='dKKBJ'><fieldset id='dKKBJ'></fieldset></dl></div>

      3. <tfoot id='dKKBJ'></tfoot>

              <small id='dKKBJ'></small><noframes id='dKKBJ'>

                <tbody id='dKKBJ'></tbody>
                  <bdo id='dKKBJ'></bdo><ul id='dKKBJ'></ul>
                  <legend id='dKKBJ'><style id='dKKBJ'><dir id='dKKBJ'><q id='dKKBJ'></q></dir></style></legend>
                • 本文介绍了在 Owin 启动类中指定域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我创建了一个自托管 Owin/SignalR 应用程序,其代码类似于本教程中的代码:

                  I've created a self hosting Owin/SignalR app with code similar to the code in this tutorial:

                  SignalR 自托管教程

                  一切正常,但为了安全起见,我想将其限制为仅允许来自特定远程站点的消息.换句话说,我想替换app.UseCors(CorsOptions.AllowAll);"符合代码以将应用程序限制为仅响应来自我定义的 URL 的消息,即只允许来自例如 http://www.remote_site 的消息.com 什么的.有什么简单的方法可以做到这一点?

                  Everything works, but for security-sake, I'd like to limit it to only allow messages from a specific remote site. In other words, I'd like to replace the "app.UseCors(CorsOptions.AllowAll);" line with code to confine the app to only responding to messages from a URL that I define, i.e. only allow messages from, say, http://www.remote_site.com or something. Is there any easy way to do this?

                  作为参考,这里是我的 SignalR 启动类的代码:

                  For reference, here is the code for my SignalR startup class:

                  using System;
                  using Microsoft.AspNet.SignalR;
                  using Microsoft.Owin.Hosting;
                  using Owin;
                  using Microsoft.Owin.Cors;
                  
                  namespace SignalRSelfHost
                  {
                      public class Startup
                      {
                          public void Configuration(IAppBuilder app)
                          {
                              app.UseCors(CorsOptions.AllowAll);
                              app.MapSignalR();
                  
                          // How do I only allow a specific URL instead of the "CorsOptions.AllowAll" option?             
                          }
                      }
                  }
                  

                  推荐答案

                  下面是 Owin Startup 类的完整实现:

                  Here is the full implementation of the Owin Startup class:

                  using System.Threading.Tasks;
                  using Microsoft.Owin;
                  using Owin;
                  using Microsoft.Owin.Cors;
                  using System.Web.Cors;
                  
                  [assembly: OwinStartup(typeof(SignalRSelfHost.Startup))]
                  
                  namespace SignalRSelfHost
                  {
                      public class Startup
                      {
                  
                          public void Configuration(IAppBuilder app)
                          {
                              var policy = new CorsPolicy()
                              {
                                  AllowAnyHeader = true,
                                  AllowAnyMethod = true,
                                  SupportsCredentials = true
                              };
                  
                              policy.Origins.Add("domain"); //be sure to include the port:
                  //example: "http://localhost:8081"
                  
                              app.UseCors(new CorsOptions
                              {
                                  PolicyProvider = new CorsPolicyProvider
                                  {
                                      PolicyResolver = context => Task.FromResult(policy)
                                  }
                              });
                  
                              app.MapSignalR();
                          }
                      }
                  }
                  

                  此外,如果您希望服务器接受域列表,只需将它们添加到 Origins.

                  Also, if you want to server to accept a list of domains, you simply add them to the Origins.

                  希望这会有所帮助!祝你好运!

                  Hope this helps! Good luck!

                  这篇关于在 Owin 启动类中指定域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  C# namespace alias - what#39;s the point?(C# 命名空间别名 - 有什么意义?)
                  Using Xpath With Default Namespace in C#(在 C# 中使用具有默认命名空间的 Xpath)
                  Generating an EDMX from a DB2 Database(从 DB2 数据库生成 EDMX)
                  IBM .NET Data Provider Connection String issue with Library List(库列表的 IBM .NET 数据提供程序连接字符串问题)
                  .NET DB2 OLEDB pre-requisites(.NET DB2 OLEDB 先决条件)
                  Referring to Code in IBM.Data.DB2 makes that Assembly Unavailable to the rest of my Solution(引用 IBM.Data.DB2 中的代码使该程序集对我的解决方案的其余部分不可用)
                      <bdo id='GmNve'></bdo><ul id='GmNve'></ul>
                        <tbody id='GmNve'></tbody>

                      <legend id='GmNve'><style id='GmNve'><dir id='GmNve'><q id='GmNve'></q></dir></style></legend>

                      <small id='GmNve'></small><noframes id='GmNve'>

                        • <i id='GmNve'><tr id='GmNve'><dt id='GmNve'><q id='GmNve'><span id='GmNve'><b id='GmNve'><form id='GmNve'><ins id='GmNve'></ins><ul id='GmNve'></ul><sub id='GmNve'></sub></form><legend id='GmNve'></legend><bdo id='GmNve'><pre id='GmNve'><center id='GmNve'></center></pre></bdo></b><th id='GmNve'></th></span></q></dt></tr></i><div id='GmNve'><tfoot id='GmNve'></tfoot><dl id='GmNve'><fieldset id='GmNve'></fieldset></dl></div>
                            <tfoot id='GmNve'></tfoot>