うにasp.net 強https全体。
質問
約6ヶ月前からロサイトが要求する必要がover https.の時に見るためあらゆるご要望にお、ページhttps通信のためのチェックでのページのロードイベントです。の場合は、以httpいます。リダイレクト(す"https://example.com")
がより良い方法--理想的に一部の設定をします。config?
解決
ご利用くださいHSTS
から http://www.hanselman.com/blog/HowToEnableHTTPStrictTransportSecurityHSTSInIIS7.aspx
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"
redirectType="Permanent" />
</rule>
</rules>
<outboundRules>
<rule name="Add Strict-Transport-Security when HTTPS" enabled="true">
<match serverVariable="RESPONSE_Strict_Transport_Security"
pattern=".*" />
<conditions>
<add input="{HTTPS}" pattern="on" ignoreCase="true" />
</conditions>
<action type="Rewrite" value="max-age=31536000" />
</rule>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
独自の回答 (交換は、上記4月-2015年)
基本的には
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.Request.IsSecureConnection.Equals(false) && HttpContext.Current.Request.IsLocal.Equals(false))
{
Response.Redirect("https://" + Request.ServerVariables["HTTP_HOST"]
+ HttpContext.Current.Request.RawUrl);
}
}
このように。asax.cs(た。asax.vb)
あまりないと思いますを知る方法を指定することもできます。config
他のヒント
その他のものでなければならないことで利用 HSTS により厳しい輸送の安全保障"ヘッダのブラウザです。ブラウザのサポートしていること(現在では、主にChrome、Firefoxとい)ですが、この一度の設定、ブラウザな要求のサイトHTTP上で、代わりに訳してHTTPSに対して、必要な発行します。うことの組み合わせにリダイレクトからのHTTP:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
switch (Request.Url.Scheme)
{
case "https":
Response.AddHeader("Strict-Transport-Security", "max-age=300");
break;
case "http":
var path = "https://" + Request.Url.Host + Request.Url.PathAndQuery;
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", path);
break;
}
}
ブラウザなHSTS知だけを無視するヘッダものの、依然として車のスイッチにより、計算書および送信される*HTTPS.
のIIS7モジュールまたはリダイレクト.
<rewrite>
<rules>
<rule name="Redirect HTTP to HTTPS" stopProcessing="true">
<match url="(.*)"/>
<conditions>
<add input="{HTTPS}" pattern="^OFF$"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther"/>
</rule>
</rules>
</rewrite>
利用の方ASP.NET MVC.きの場合、次のコマンドを実行する力ではSSL/TLS over HTTPSのサイトは二つの方法:
っているという
1-追加のRequireHttpsAttributeのグローバルフィルタ:
GlobalFilters.Filters.Add(new RequireHttpsAttribute());
2-力防Csrfトークンを使用してSSL/TLS:
AntiForgeryConfig.RequireSsl = true;
3-クッキーを必要とするHTTPSのデフォルトに変更します。設定ファイル:
<system.web>
<httpCookies httpOnlyCookies="true" requireSSL="true" />
</system.web>
4-利用のNWebSec.Owin NuGetパッケージの追加は、次のコードにより厳しい輸送のセキュリティ南のサイトです。トなどのプリロードの指令は下記を提出しのサイト HSTSプリロードサイト.詳細情報 こちらの や こちらの.ることがありますのでご注意くだ使用していないOWINがあります。config方法だけに NWebSec サイトです。
// app is your OWIN IAppBuilder app in Startup.cs
app.UseHsts(options => options.MaxAge(days: 30).Preload());
5を使用NWebSec.Owin NuGetパッケージの追加は、次のコードを公開鍵のピン止め(HPKP)のサイトです。詳細情報 こちらの や こちらの.
// app is your OWIN IAppBuilder app in Startup.cs
app.UseHpkp(options => options
.Sha256Pins(
"Base64 encoded SHA-256 hash of your first certificate e.g. cUPcTAZWKaASuYWhhneDttWpY3oBAkE3h2+soZS7sWs=",
"Base64 encoded SHA-256 hash of your second backup certificate e.g. M8HztCzM3elUxkcjR2S5P4hhyBNf6lHkmjAHKhpGPWE=")
.MaxAge(days: 30));
6-、httpsスキームの任意のURLを使用します。 コンテンツセキュリティポリシー(CSP) HTTPヘッダおよび Subresource完全性(スリラン) いきまimitのスキームの一部ブラウザを推奨いたします。で明示的に約HTTPS.例えば
<script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.4/bootstrap.min.js"></script>
The Easy Way
をご利用 ASP.NET MVC定型 Visual Studioプロジェクトテンプレートを生成するプロジェクトのすべてのことなどを内蔵しています。また、コード GitHub.
できない場合は設定でIIS、理由の如何にかかわらず、いくHTTPモジュールのリダイレクト専用に作成する方法もあります。
using System;
using System.Web;
namespace HttpsOnly
{
/// <summary>
/// Redirects the Request to HTTPS if it comes in on an insecure channel.
/// </summary>
public class HttpsOnlyModule : IHttpModule
{
public void Init(HttpApplication app)
{
// Note we cannot trust IsSecureConnection when
// in a webfarm, because usually only the load balancer
// will come in on a secure port the request will be then
// internally redirected to local machine on a specified port.
// Move this to a config file, if your behind a farm,
// set this to the local port used internally.
int specialPort = 443;
if (!app.Context.Request.IsSecureConnection
|| app.Context.Request.Url.Port != specialPort)
{
app.Context.Response.Redirect("https://"
+ app.Context.Request.ServerVariables["HTTP_HOST"]
+ app.Context.Request.RawUrl);
}
}
public void Dispose()
{
// Needed for IHttpModule
}
}
}
それだけでコンパイルでDLLとして追加しますを参考にプロジェクトとこの場所です。config:
<httpModules>
<add name="HttpsOnlyModule" type="HttpsOnly.HttpsOnlyModule, HttpsOnly" />
</httpModules>
必要なものは:
1)キーの追加中。configによっては、生産段階でサーバを以下のように
<add key="HttpsServer" value="stage"/>
or
<add key="HttpsServer" value="prod"/>
2)内です。asaxファイルに以下の内容を追加します。
void Application_BeginRequest(Object sender, EventArgs e)
{
//if (ConfigurationManager.AppSettings["HttpsServer"].ToString() == "prod")
if (ConfigurationManager.AppSettings["HttpsServer"].ToString() == "stage")
{
if (!HttpContext.Current.Request.IsSecureConnection)
{
if (!Request.Url.GetLeftPart(UriPartial.Authority).Contains("www"))
{
HttpContext.Current.Response.Redirect(
Request.Url.GetLeftPart(UriPartial.Authority).Replace("http://", "https://www."), true);
}
else
{
HttpContext.Current.Response.Redirect(
Request.Url.GetLeftPart(UriPartial.Authority).Replace("http://", "https://"), true);
}
}
}
}
場合は、SSLをサポートプおります。べることができたのでhttps on/off)で利用できます[RequireHttps]属性を他のコントローラー/コントローラのアクションだ。
もよりますが、ブランドのバランスのウェブmuxする上で重要な要素であるhttpヘッダ X-WebMux-SSL-termination: true
を図るた通信します。詳細はこちら http://www.cainetworks.com/support/redirect2ssl.html
マジョーさん、"これは与えてくれて、リダイレクトループを実行します。前のコードでの現代美術館などがあります。ご意見募集–Joe月8'11 4:13"
これは起こっとだと思っていったい何が起こっていたのであることがありました負荷分散装置解除のSSL請求の前にWebサーバです。なので、自分のウェブサイトを常に意識しての要求があったのに"http"でもブラウザの依頼で"https".
今このビットhackyが、どのように働くための"JustRedirected"プロパティというレバレッジの人でにリダイレクトします。そこで、試験のための特別な条件が保証するものにリダイレクトされた、この物件に格納された値セッション)以前にリダイレクト.場合でも、http/httpsの条件のためリダイレクションを満たい時はバイパスにリダイレクトの論理リセットの"JustRedirected"セッションの値をfalseになります。る必要がありま自分の条件付き検定ロジックだが、ここでもシンプルな実装の物件:
public bool JustRedirected
{
get
{
if (Session[RosadaConst.JUSTREDIRECTED] == null)
return false;
return (bool)Session[RosadaConst.JUSTREDIRECTED];
}
set
{
Session[RosadaConst.JUSTREDIRECTED] = value;
}
}
私はスローマセントです。 の場合 へのアクセス権を持っているIISサーバ側できますので、その力にHTTPSを用い、プロトコルランタイム環境を含んでいます。例えば、というサイト Blah.でIISまの設定につサイト: Blah, は、 Blah(リダイレクト).のための Blah のみの設定 HTTPS
結合( FTP
が必要な場合は、必ず力でセキュアな接続していくでしょう。のための Blah(リダイレクト) のみの設定 HTTP
拘束力を有します。最後に、 HTTPリダイレクト 部門 Blah(リダイレクト) 必ず301へのリダイレクト https://blah.com
, で、正確な行先を有効にします。必ず各サイトのIISが差しをその 独自の rootフォルダのその他の ます。config すべて取得しま螺ます。また余白に記入してください HSTS
設定されおHTTPSedサイトにその後続の要求によりブラウザには常に強HTTPS、リダイレクトが発生します。
これは、充実の回答に基づき@オンライン旅行会社エクスペディ狩りです。追加機能を WebApplication
クラス Global.asax.cs
:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
// Allow https pages in debugging
if (Request.IsLocal)
{
if (Request.Url.Scheme == "http")
{
int localSslPort = 44362; // Your local IIS port for HTTPS
var path = "https://" + Request.Url.Host + ":" + localSslPort + Request.Url.PathAndQuery;
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", path);
}
}
else
{
switch (Request.Url.Scheme)
{
case "https":
Response.AddHeader("Strict-Transport-Security", "max-age=31536000");
break;
case "http":
var path = "https://" + Request.Url.Host + Request.Url.PathAndQuery;
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", path);
break;
}
}
}
(めにSSL上での構築がパドックのためのプロジェクト)
->単に追加[RequireHttps】トップのクラスHomeController:コントローラです。
->追加GlobalFilters.浄が可能です。Add(新RequireHttpsAttribute());の"protected void Application_Start()'メソッドです。asax.csファイルです。
る力を全体への応用*HTTPS.
私は何かを探して最善の実践があっても無視されるのでご注意見は以下のできる完成されました。これはそのまま保存を受けます。
を使用 設定ファイル (例えば、asp.net ウェブサイト) https://blogs.msdn.microsoft.com/kaushal/2013/05/22/http-to-https-redirects-on-iis-7-x-and-higher/
または自分のサーバー https://www.sslshopper.com/iis7-redirect-http-to-https.html
[問] 単純に以下のコードがあるという
<system.webServer>
<rewrite>
<rules>
<rule name="HTTP/S to HTTPS Redirect" enabled="true"
stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{SERVER_PORT_SECURE}" pattern="^0$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}"
redirectType="Permanent" />
</rule>
</rules>
</rewrite>
ご利用の場合ASP.NET 核きしみくださいnugetパッケージSaidOut.AspNetCore.HttpsWithStrictTransportSecurity.
それだけに追加する必要があり
app.UseHttpsWithHsts(HttpsMode.AllowedRedirectForGet, configureRoutes: routeAction);
このまま追加HTTP StrictTransportSecurityヘッダの全ての請求を利用しhttpsスキームです。
コード例、および文書化 https://github.com/saidout/saidout-aspnetcore-httpswithstricttransportsecurity#example-code
にIIS10(Windows10は、サーバ2016年度),バージョン1709以降、新たに単純なオプションを可能にするHSTSた。
Microsoft記述の優位性を図るための新しいアプローチ こちらの, で、多くの異なる事例をどのように実施するかについプログラムに変更または直接編集のApplicationHost.configファイルによっています。configがでIISレベルでなく、個人サイト)です。ApplicationHost.configでC:\Windows\System32\inetsrv\config.
私は次の例の方法はこちらを避けるリンクの腐.
方法1 編集のApplicationHost.configファイルを直接
との間で <site>
タグに追加します:
<hsts enabled="true" max-age="31536000" includeSubDomains="true" redirectHttpToHttps="true" />
方法2 -コマンドライン:を記憶させることができます。からの高コマンドプロンプト(右マウスではCMD、管理者権限で実行して).忘れずにスワップContosoのサイトの名前を指定します。に表示されているとおりIISマネージャ。
c:
cd C:\WINDOWS\system32\inetsrv\
appcmd.exe set config -section:system.applicationHost/sites "/[name='Contoso'].hsts.enabled:True" /commit:apphost
appcmd.exe set config -section:system.applicationHost/sites "/[name='Contoso'].hsts.max-age:31536000" /commit:apphost
appcmd.exe set config -section:system.applicationHost/sites "/[name='Contoso'].hsts.includeSubDomains:True" /commit:apphost
appcmd.exe set config -section:system.applicationHost/sites "/[name='Contoso'].hsts.redirectHttpToHttps:True" /commit:apphost
その他の方法にMicrosoftの提供する論文の方が良いかもしれないオプションの場合は、主催の環境が限られています。
こIIS10版1709はWindows10がWindowsサーバ2016年までにリリーストラックとんとして発売されるパッチまたはサービスパックです。見 こちらの 詳細について1709.