在asp.net中有没有限制只从本地主机访问网页的方法?如何限制只有本地主机的页面访问?
8
A
回答
0
,这可能是一个解决方案:
protected void Page_Load(object sender, EventArgs e)
{
string localhost = Request.Url.Authority;
if (localhost.IndexOf("localhost") != 0)
Response.Redirect("defalut.aspx");
}
6
如果你想为一个“网页”这样做,那么我会用IsLocal,但如果你想我会使用一个子目录的解决方案URL重写2 。http://www.microsoft.com/web/gallery/install.aspx?appid=urlrewrite2。如果你还没有安装它,那就去做吧,因为它非常有用。我相信它将成为IIS8的标准。
那么这下<system.webServer/>
<rewrite>
<rules>
<!-- if this rule matches stopProcessing any further rules -->
<rule name="Block Remote Access to Admin" stopProcessing="true" patternSyntax="ECMAScript" enabled="true">
<!-- specify secure folder matching trailing/or $ == end of string-->
<match url="projects(/|$)" ignoreCase="true" />
<conditions logicalGrouping="MatchAll">
<!-- Allow local host -->
<add input="{REMOTE_ADDR}" pattern="localhost" ignoreCase="true" negate="true" />
<add input="{REMOTE_ADDR}" pattern="127.0.0.1" negate="true" />
<add input="{REMOTE_ADDR}" pattern="::1" negate="true" />
</conditions>
<!-- by default, deny all requests. Options here are "AbortRequest" (drop connection), "Redirect" to a 403 page, "CustomResponse", etc. -->
<action type="CustomResponse" statusCode="403" statusDescription="Forbidden" statusReason="Access to this URL is restricted"/>
<!-- or send the caller to an error page, home page etc
<action type="Redirect" url="/public/forbidden.htm" redirectType="Temporary" />
-->
</rule>
<rules>
</rewrite>
12
if (!HttpContext.Current.Request.IsLocal)
{
Response.Status = "403 Forbidden";
Response.End();
}
0
抢添加到您的web.config中的 'REMOTE_ADDR' 并运行对正则表达式。
Dim remoteAddress As String = Request.ServerVariables("REMOTE_ADDR")
If Regex.IsMatch(remoteAddress, "(::1|127\.0\.0\.1)") Then
//Call originated from localhost, display page..
End If
我要补充::1
是,如果您的服务器配置为IPv6的
相关问题
- 1. 如何限制在Python中访问本地主机的页面?
- 2. Tomcat:限制访问本地主机的/只有一个/ webapp
- 3. 限制WCF服务访问只有本地主机
- 4. 如何限制ActiveMQ的JMX API只能访问本地主机/内部网?
- 5. Apache的访问限制,除非从本地主机
- 6. jQuery的没有本地主机页面
- 7. 如何从android访问本地主机?
- 8. 无法访问本地主机上的某些PHP页面
- 9. 如何保护webapp只能通过本地主机访问?
- 10. 限制访问页面php
- 11. 如何限制IP地址范围的页面访问?
- 12. 限制页面访问只能从指定页面输入?
- 13. 限制访问页面只允许从某个页面
- 14. 通过Microsoft Edge扩展后台访问本地主机页面
- 15. OSX无法访问本地主机,只有username.local
- 16. Asp - 只有本地主机可以访问共享驱动器
- 17. 限制asmx访问本地
- 18. 允许从本地主机通过Squid访问本地主机
- 19. 限制只能到本地主机的PHP文件
- 20. 限制selenium 2端口 - 仅限本地主机 - 无外部IP访问
- 21. 如何从我的Android手机访问我的本地主机
- 22. 如何访问ASP.NET本地主机网站上的Android手机
- 23. Magento本地主机只有主页工作
- 24. 只能访问本地主机上的asp.net应用程序
- 25. 如何限制Apache只接受来自本地主机的特定url请求?
- 26. 限制访问php中的页面
- 27. 如何授予本地主机权限?
- 28. DirectoryInfo的只有从本地主机
- 29. 只有本地主机的RMI?
- 30. 如何修复在URL中使用IP地址而不是本地主机时WAMP页面访问的问题
你想要什么,如果非本地主机请求时发生本地主机是如何出现? – freefaller 2012-08-09 08:37:06
限制访问 – zirus 2012-08-09 08:39:17
是的,我认为我们理解访问是受限制的......但是完全**应该发生什么**? **用户应该看到什么**?他们是否被指引到某个地方? (如果你正在回复一个人,你需要输入一个'@',然后输入用户名,否则他们将不会收到通知) – freefaller 2012-08-09 08:45:22