asp.net-mvc - 仅允许来自同一网络服务器的请求的操作

标签 asp.net-mvc security

我有一个 MVC Controller ,它公开了 Initialise Action .托管在同一 IIS 上的其他虚拟 Web 应用程序将需要访问此 Action.
出于安全原因,只有来自同一 Web 服务器(托管 MVC 应用程序)的请求才需要被授予访问此 Iniliase 方法的权限。

有人可以帮助如何实现这一目标吗?我们无法使用 localhost 进行验证,因为此应用程序将托管在不支持 locahost 请求的 Azure 中。

最佳答案

我的回答是关于限制服务器端请求。

调用Initialise的网站需要向 http://www.example.com/controller/Initialise 提出请求而不是 http://localhost/controller/Initialise (当然,用您的域和 Controller 名称替换 www.example.comcontroller)。

HttpRequest.IsLocal应该在您的 Controller 操作中检查:

if (!Request.IsLocal)
{
    throw new SecurityException();
}

这将拒绝任何不是来自本地主机的请求。这种方法假设调用站点和请求站点共享相同的 IP 地址 - 文档说明这应该有效:

The IsLocal property returns true if the IP address of the request originator is 127.0.0.1 or if the IP address of the request is the same as the server's IP address.



用于限制客户端请求谷歌“csrf 缓解”。

关于asp.net-mvc - 仅允许来自同一网络服务器的请求的操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20593972/

相关文章:

asp.net-mvc - 为什么选择 Asp.net MVC 而不是 Asp.net MVP

security - 通过 SSH 查找并删除?

java - 火狐 "ssl_error_no_cypher_overlap"错误

php - 我在哪里可以找到 web 项目 "security checklist?"

github protected 分支机构不提供任何真正的安全性

asp.net-mvc - 将变量从 [HttpPost] 方法传递到 [HttpGet] 方法

javascript - 使用 mvc 进行数据绑定(bind)的多 handle slider

c# - MVC 5、EF 6 Barebones 无效的列名称 'Model'

database - Ubuntu 网络服务器权限

asp.net-mvc - BeginForm 与 IEnumerable