简体   繁体   English

从 Http 到 Https 的重定向仅在安装了应用程序的 iis 服务器浏览器内部有效

[英]Redirection from Http to Https works only internally on iis server browser where is app installed

Redirection from http to https not working properly, below is my code used in web.config file从 http 到 https 的重定向无法正常工作,下面是我在 web.config 文件中使用的代码

   <rewrite>
        <rules>
            <rule name="http to https" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="^OFF$" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Temporary" />
            </rule>
        </rules>
    </rewrite>

I have a valid SSL certificate, and I disable Require SSL.我有一个有效的 SSL 证书,并且我禁用了 Require SSL。

with this code in global.asax file在 global.asax 文件中使用此代码

      protected void Application_BeginRequest()
    {
        if (!Request.IsSecureConnection)
        {
            Response.Redirect(Request.Url.AbsoluteUri.Replace("http://", "https://"));
        }
    }

I tried all argument but nothing works, redirection works only if I open the browser from the server it self.我尝试了所有参数,但没有任何效果,只有当我从服务器打开浏览器时,重定向才有效。

You could do the same from the IIS Manager:您可以从 IIS 管理器执行相同操作:

Open IIS Manager -> Select your site from Connections Panel (in left side) -> Click on HSTS... option from Action Panel(in right side) -> Check the "Enable" Option and "Redirect Http to Https" -> Now click the "OK" button.打开 IIS 管理器 -> 从连接面板(左侧)中选择您的站点 -> 从操作面板(右侧)中单击 HSTS... 选项 -> 选中“启用”选项和“将 Http 重定向到 Https” ->现在单击“确定”按钮。

Hope it will work for you.希望它对你有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IIS 上从 http 到 https 的 URL 重写不起作用, - URL Rewrite on IIS from http to https is not working, IIS服务器路由和重定向 - IIS server routing and redirection IIS 7.5 URL重写-帐户控制器从http重定向到https,其他所有内容从https重定向到http - IIS 7.5 URL Rewrite - Redirect from http to https for account controller but from https to http for everything else Server 2019上的ASP.NET 4.7-HTTPS提供HTTP 503-服务不可用(在Http上运行) - ASP.NET 4.7 on Server 2019 - HTTPS giving HTTP 503 - Service Unavailable (Works on Http) 读卡器程序可在本地系统中运行,但不能从IIS服务器中运行 - Card Reader Program works in Local system But not from IIS server 从HTTPS协议发出请求时,IIS URL重写规则(模式)无法识别{HTTP_HOST} - IIS URL rewrite rule(Pattern) doe not recognize {HTTP_HOST} when request is made from HTTPS protocol 在IIS7.5中使用C#MVC从HTTP重定向到HTTPS并重定向到新域 - Redirect from HTTP to HTTPS and to a new domain with C# MVC in IIS7.5 当MVC应用程序托管在ASP.NET Devlopment服务器上的IIS..works上时,在IIS上未显示图像 - Image not showing on IIS when MVC app is hosted on IIS..works on ASP.NET Devlopment server just fine 无法通过 HTTPS 从本地 IIS 连接到 SQL Server 数据库 - Can't connect to SQL Server database from Local IIS over HTTPS 当在 IIS 中发布 .net 核心 web 应用程序的示例项目时,出现 Z293C9EA246FF99875DC6F62A5601 内部服务器错误。 - When Publish sample project of .net core web app in IIS getting HTTP Error 500.19 Internal Server Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM