2012-08-09 15 views
8

asp.netにlocalhostからのWebページへのアクセスを制限する方法はありますか?ページアクセスをローカルホストに限定する方法?

+0

あなたは非ローカルホストの要求が行われた場合に発生する何をしたいかに設定されている場合はlocalhostが表示されますどのようにでしょうか? – freefaller

+0

アクセスを制限する – zirus

+1

はい、私はアクセスが制限されていることを理解していると思いますが、まさに**何が起こるべきですか? **どのような**ユーザーが表示する必要がありますか?彼らはどこかに向かうべきだろうか?あなたが個人に返信している場合は、ユーザー名の後ろに '@'をつける必要があります。そうでなければ、彼らは通知を受け取りません) – freefaller

答えて

0

これは解決策が考えられます。

protected void Page_Load(object sender, EventArgs e) 
{ 
    string localhost = Request.Url.Authority; 
    if (localhost.IndexOf("localhost") != 0) 
     Response.Redirect("defalut.aspx"); 
} 
6

あなたは、「Webページ」のためにこれをしたい場合は、私がの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

'REMOTE_ADDR' をつかんで、正規表現に対してそれを実行するの下で、あなたのweb.configファイルにこれを追加します。

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

関連する問題