Asp.net'de bir web sayfasına erişimi yalnızca localhost'tan sınırlamak için bir yol var mı?Sayfa erişimini yalnızca localhost ile sınırlama nasıl?
8
A
cevap
0
bu bir çözüm olabilir: Bir "web sayfası" için bunu yapmak istiyorsanız
protected void Page_Load(object sender, EventArgs e)
{
string localhost = Request.Url.Authority;
if (localhost.IndexOf("localhost") != 0)
Response.Redirect("defalut.aspx");
}
6
sonra isLocal kullanmayı tercih ediyorum, ama sen Kullanayım bir alt dizin çözümünü istiyorsanız URL 2 yeniden yazın http://www.microsoft.com/web/gallery/install.aspx?appid=urlrewrite2. Bunu zaten yüklemediyseniz, gidin ve çok kullanışlı olduğu için alın. IIS8'de standart olacağına inanıyorum.
Sonra <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
Grab altında web.config için 'REMOTE_ADDR' bu ekleyebilir ve bir regex karşı çalıştırın.
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
Ben ::1
eklemek gerekir sunucu IPv6
olmayan bir localhost isteğinde bulunulursa, ne olmasını istiyorsun için yapılandırılmış olup olmadığını localhost nasıl görüneceğini nedir? – freefaller
kısıtlamak erişim – zirus
Evet, erişim kısıtlı olduğunu anlıyoruz sanırım ... ama tam olarak ne **? ** Kullanıcı ne görmeli? Onlar bir yere yönlendirilebilir mi? (Bir kişiye cevap veriyorsanız, bir '@' ve ardından kullanıcı adlarını yazmanız gerekir, aksi halde bir bildirim alamazsınız) – freefaller