Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
235 views
in Technique[技术] by (71.8m points)

asp.net - HTTP到HTTPS不适用于我的asp.net网站(HTTP to HTTPS not working for my asp.net website)

I tried almost all upvoted suggestions related to web.config changes for http to https redirection.

(我尝试了几乎所有有关将web.config更改从http重定向到https重定向的建议。)

Best way in asp.net to force https for an entire site?

(在asp.net中对整个站点强制使用https的最佳方法?)

But its not working for me for my ASP.net site.

(但是它对我的ASP.net网站不起作用。)

I use godaddy shared hosting and have multiple sites in my account.

(我使用godaddy共享托管,帐户中有多个站点。)

I have ssl enabled only for one website and have to add it to filter so that other sites in the same account are not redirected to https.

(我仅对一个网站启用了ssl,并且必须将其添加到过滤器中,以便同一帐户中的其他网站不会重定向到https。)

Here's my web.config:

(这是我的web.config:)

 <rewrite> <rules> <rule name="HTTP to HTTPS redirect" stopProcessing="true" enabled="true"> <match url="singledomain.*" /> <conditions> <add input="{HTTPS}" pattern="off" ignoreCase="true" /> </conditions> <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" /> </rule> </rules> </rewrite> 

I can access the site currently by both http and https.

(我可以同时通过http和https访问该站点。)

But it never redirects from http to https.

(但是它永远不会从http重定向到https。)

Can someone please assist if I the match condition is correct and if that is what is the problem?

(如果我的比赛条件正确,那有什么问题可以帮助吗?)

Thanks.

(谢谢。)

  ask by Ganesh S translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Found the solution here: https://stackoverflow.com/a/17066105/2535756 Posting the code here which worked:

(在这里找到解决方案: https: //stackoverflow.com/a/17066105/2535756在此处发布有效的代码:)

<rewrite>
      <rules>
        <rule name="HTTP to HTTPS" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="(singledomain.com.*)" />
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          </conditions>
          <action type="Redirect" redirectType="Permanent"  url="https://{HTTP_HOST}/{R:1}" />
        </rule>
      </rules>
    </rewrite>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...