【问题标题】:Can I have application listening in multiple ports? (one for public and one for private use)我可以让应用程序监听多个端口吗? (一公用一私用)
【发布时间】:2021-01-09 11:01:12
【问题描述】:

我有一个.NET MVC 应用程序,它具有多种功能。

我可以通过如下所示配置不同的端口将这个应用程序作为单个应用程序托管在IIS 中吗?

  1. Website to view product              localhost:80/index.cs               
    
  2. API exposed for internal usage       localhost:23004/Listporducts();     
    

有可能吗?

实时场景:我在Azure IaaS VM 中托管应用程序。我的内部应用程序将使用API,客户应使用公共website

【问题讨论】:

  • 你的意思是网站和API在同一个应用程序中,你只希望23004端口可以访问web api吗?
  • 是的,网站和 API 在同一个应用程序中。我希望端口 23004(或任何其他端口)访问 Web API。

标签: asp.net asp.net-mvc windows iis port


【解决方案1】:

在我看来,最简单的方法是防止 Azure VM 不打开 23004 端口。详情可以参考这个article

如果你不想使用 Azure MV,你可以考虑在 web api 中使用自定义过滤器属性来检查请求是否是本地的。如果请求不是从本地发送的,则可以直接返回 404 not found 错误。

更多关于如何使用自定义过滤属性的细节,你可以参考这个article

public class CustomActionAttribute : FilterAttribute, IActionFilter { 
    public void OnActionExecuting(ActionExecutingContext filterContext) { 
        if (filterContext.HttpContext.Request.IsLocal) { 
            filterContext.Result = new HttpNotFoundResult(); 
        } 
    }

    public void OnActionExecuted(ActionExecutedContext filterContext) { 
        // not yet implemented 
    } 
}

【讨论】:

  • 我想为内部 azure 服务打开 23004 端口。所以我不能在 NSG 级别阻止。 [Azure Functions 等内部服务]
猜你喜欢
  • 2012-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-30
  • 2011-01-06
  • 1970-01-01
相关资源
最近更新 更多