I have URL Rewrite rule in IIS 10 to enforce all http request to https this way and it works perfect.
<rewrite><rules><rulename="HTTP/S to HTTPS Redirect"enabled="true"stopProcessing="true"><matchurl="(.*)"/><conditionslogicalGrouping="MatchAny"><addinput="{SERVER_PORT_SECURE}"pattern="^0$"/></conditions><actiontype="Redirect"url="https://{HTTP_HOST}{REQUEST_URI}"redirectType="Permanent"/></rule></rules></rewrite>
Here comes the twist.. I am hosting one ClickOnce application on the same server and when installer try to download the application then it gives error
URLDownloadToCacheFile failed with HRESULT '-2146697202' Error: An error occurred trying to download
Although URL is propery accessed via browser which is mentioned in this error.
As per microsoft documents error description is
if the setup URL of the ClickOnce application being installed is redirected from a non-secure to a secure site (or vice-versa), the installation will fail because the Internet Explorer warning interrupts it.
** Installer is using IE internally to download the manifest file
Now to tackle this situation I have made IP binding with my site in IIS so i would access the file with IP but when I do access the site with IP then the above rule also trigger for it and redirects to HTTPS and browser give an error again because hostname
mismatch in SSL Certs. I want to bypass this redirect rule for my site when it browsed with IP.
I donot know how I can modify the above rule by having additional condition or what will be the new rule to bypass this https redirection when access via IP.
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
When I enable this rule then http and https redirect with domain name does not work and its stuck in some loop and after sometime browser says its unexpected redirects and when I try to access with IP then it redirects to https.
I just tried to open the website from browser and in that case website was not opening either. TBH I didnot tried with clickonce application but I am sure it will not work.
None
0 Points
3 Posts
IIS URL Rewrite Rule
Dec 17, 2017 03:48 PM|ArslanP|LINK
I have URL Rewrite rule in IIS 10 to enforce all http request to https this way and it works perfect.
Here comes the twist.. I am hosting one ClickOnce application on the same server and when installer try to download the application then it gives error URLDownloadToCacheFile failed with HRESULT '-2146697202' Error: An error occurred trying to download
Although URL is propery accessed via browser which is mentioned in this error.
As per microsoft documents error description is
if the setup URL of the ClickOnce application being installed is redirected from a non-secure to a secure site (or vice-versa), the installation will fail because the Internet Explorer warning interrupts it.
** Installer is using IE internally to download the manifest file
Now to tackle this situation I have made IP binding with my site in IIS so i would access the file with IP but when I do access the site with IP then the above rule also trigger for it and redirects to HTTPS and browser give an error again because hostname mismatch in SSL Certs. I want to bypass this redirect rule for my site when it browsed with IP.
I donot know how I can modify the above rule by having additional condition or what will be the new rule to bypass this https redirection when access via IP.
All-Star
40565 Points
6233 Posts
Microsoft
Re: IIS URL Rewrite Rule
Dec 18, 2017 07:26 AM|Fei Han - MSFT|LINK
Hi ArslanP,
Welcome to ASP.NET forum.
To achieve it, you can try to specify additional logical operations in Conditions collection.
With Regards,
Fei Han
None
0 Points
3 Posts
Re: IIS URL Rewrite Rule
Dec 18, 2017 11:56 AM|ArslanP|LINK
Hi Fei Han,
Thanks for your reply.
I tried as you suggested but it doesnot work.
Here is my final code snippet.
<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$" />
<add input="{HTTP_HOST}" pattern="109.203.xxx.xxx" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
When I enable this rule then http and https redirect with domain name does not work and its stuck in some loop and after sometime browser says its unexpected redirects and when I try to access with IP then it redirects to https.
All-Star
48720 Points
18188 Posts
Re: IIS URL Rewrite Rule
Dec 18, 2017 12:20 PM|PatriceSc|LINK
Hi,
And it doesn't work if you are just using an https link to your ClickOnce application?
None
0 Points
3 Posts
Re: IIS URL Rewrite Rule
Dec 18, 2017 12:31 PM|ArslanP|LINK
I just tried to open the website from browser and in that case website was not opening either. TBH I didnot tried with clickonce application but I am sure it will not work.
Regards,
Participant
990 Points
475 Posts
Re: IIS URL Rewrite Rule
Dec 25, 2017 08:27 AM|zxj|LINK
Hi ArslanP,
Have you tried to get help from clickonce related forum: https://social.msdn.microsoft.com/Forums/windows/en-US/home?forum=winformssetup
Regards,
zxj