2017-04-25 5 views
2

私はASP.NET MVC Webアプリケーションを持っています。httpsデフォルトのASP.NET MVC

私はAzureのWebアプリケーションでそれをアップロードすると、ウェブサイトは、私はそれが常にhttps://をする必要がhttp://

を持っています。

どうすればいいですか?

私はそれがあまりにも広い質問かもしれないことを知っていますが、あなたは私にいくつかの助言を与えることができますか?

enter image description here

私はそれがhttpsである必要が

答えて

4

私のプロジェクトでは、このようなプロパティを設定://常に。

HTTPSを強制するURL書き換えルールを作成できます。

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
    <rewrite> 
     <rules> 
     <!-- BEGIN rule TAG FOR HTTPS REDIRECT --> 
     <rule name="Force HTTPS" enabled="true"> 
      <match url="(.*)" ignoreCase="false" /> 
      <conditions> 
      <add input="{HTTPS}" pattern="off" /> 
      </conditions> 
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" /> 
     </rule> 
     <!-- END rule TAG FOR HTTPS REDIRECT --> 
     </rules> 
    </rewrite> 
    </system.webServer> 
</configuration> 

また、Enforce HTTPS on your appを参照することもできます。

+0

ありがとうございました –

2

コードを使用し、web.configではなくソリューションを使用する場合は、Global.asax.csファイルで次のように記述できます。

protected void Application_BeginRequest() { 
      // Ensure any request is returned over SSL/TLS in production 
      if (!Request.IsLocal && !Context.Request.IsSecureConnection) { 
       var redirect = Context.Request.Url.ToString().ToLower(CultureInfo.CurrentCulture).Replace("http:", "https:"); 
       Response.Redirect(redirect); 
      } 
} 
+0

ありがとうございました –

関連する問題