IIS Rewrite + Vue history mode making Windows Authentication not work - vue.js

I'm creating a Vue webpage with history mode hosted on IIS. I use URL Rewrite to route any path that doesn't resolve to a static file to my index.html file, like many many forums suggested, and the Vue does client side routing from there.
However, I'm also using Windows Authentication, and any time I go to a Vue route (that doesn't match a static file) in my browser (tested on multiple), it asks for my credentials and I enter the correct ones, but it just keeps asking me again and again for my credentials, without ever letting me in. On the other hand, when I route to a static file, I log in, and it lets me in just fine and I can then go to a Vue route because I'm already logged in.
Why is IIS URL Rewrite making my authentication repeat itself and not let me in? We've been at a bit of a loss and have had to route to static file first every time to log in.
The only thing I've found is to turn off Anonymous Authentication, and it is.
Here is my web.config with the rerouting instructions:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Handle History Mode and custom 404/500" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/Dashboard/vue/dist/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
(It reroutes to /Dashboard/vue/dist/ because that contains an index.html)
Thanks!

Related

How to run vuejs files on IIS

So am using a vueJS Example as a demo for learning purposes which uses a requirejs-vue as a component loader.
when i run the server on Live-Server extension of VS-code (a simple http server), it run correctly with no problems.
However, when i run this example on IIS server (version 8.5) on windows 8.1, it through 404 Error app.vue does not exist.
Failed to load resource: the server responded with a status of 404 (Not Found)
and in the Network devtool, i can see that every module is loaded correctly, except for *.vue files,
VueJS Example :
https://plnkr.co/edit/Y2cEa3?preview
Web Config for IIS that am using:
https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Handle History Mode and custom 404/500" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
PS: i have also run an other example that uses http-vue-loader instead of requirejs-vue and IIS still throwing the same error.
We need to set mimeType for the “.vue” extension file to use httpvueloader/requiresjs_vue.
In addition, we could manually add it to a Web.Config file, which can be recognized by IIS.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".vue" mimeType="application/javascript"/>
</staticContent>
</system.webServer>
</configuration>
Feel free to let me know if the problem still exists.

IIS Rewrite Reverse Proxy getting HTTP 502 error when using SSL

I am looking for ideas/suggestions to setup/troubleshoot a configuration that allows me to debug a scenario as follows.
I am using IIS 10, Visual Studio 2017
I have a web application that posts a message to a 3rd party site.
The 3rd party site then posts a response back to my web application.
IIS has a reverse proxy (shown below) the directs the post from the 3rd party application to IIS Express where
my app is running in IIS Express (VS 2017).
All connections use SSL. IIS Express is using a self signed cert that comes with VS2017.
Calling the app running on IIS Express from the 3rd party app via the reverse proxy worked until I changed to using SSL.
(This solution requires SSL).
url="https://10.10.203.132:44349/{R:1}" -> this is the computer where my app is running in VS2017.
Now I get a 502 error subcode 3 and my app is never called. No other info in Failed request tracing
Any suggestions?
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Reverse Proxy" enabled="true" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="https://10.10.203.132:44349/{R:1}" />
</rule>
</rules>
<outboundRules>
<rule name="Ensure samesite Cookies" preCondition="Missing samesite cookie">
<match serverVariable="RESPONSE_Set_Cookie" pattern=".*" negate="false" />
<action type="Rewrite" value="{R:0}; SameSite=None" />
</rule>
<preConditions>
<preCondition name="Missing samesite cookie">
<!-- Don't remove the first line here, it does do stuff! -->
<add input="{RESPONSE_Set_Cookie}" pattern="." />
<add input="{RESPONSE_Set_Cookie}" pattern="; SameSite=None" negate="true" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
<system.webServer>
<rewrite>
<rules>
<rule name="Reverse Proxy" enabled="true" stopProcessing="true">
<match url="(.*)" />
<action type="Redirect" url="https://10.10.203.132:44349/{R:1}" appendQueryString="true" logRewrittenUrl="false" />
<conditions logicalGrouping="MatchAll">
<add input="{SERVER_PORT_SECURE}" pattern="0" /></conditions>
</rule>
</rules>
Here is another solution.
https://www.namecheap.com/support/knowledgebase/article.aspx/9953/38/iis-redirect-http-to-https
Feel free to let me know if the problem still exists.

Added SSL certificate to website, everything runs fine except if someone types https://example.com

I recently added a SSL certificate to my site. In my webconfig I added this code to force the https connection from anyway someone can type in a http connection
<httpRedirect enabled="false" destination="" exactDestination="false" childOnly="false" />
<rewrite>
<rules>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
However there is a problem, if a user types in the URL https://example.com they will be hit with the message that their connection is not private and to leave my site.
I have two questions about this.
Is my certificate wrong and that's why my domain is not being accepted as https?
And is there a way i can force someone that goes to https://example.com to get redirected to https://www.example.com?
Take a look at your site on this website https://www.sslshopper.com/ssl-checker.html#hostname=
this might give you a better understanding as to what is part of SSL

Relocating WCF service endpoint?

I've got a simple web application which has a single WCF service in the root folder:
+AppRoot
---MyService.svc
This is being modified to include a lot of new functionality, and I've split these into two separate services in different folders to represent their version:
+AppRoot
---v1
-----MyService.svc
---v2
-----MyService.svc
However, the existing consumers of this service still using v1 need to be able to access the v1 service the old URL - eg. http://services.example.com/MyService.svc.
I'd like to keep these services physically separated in their respective v1 and v2 folders, while transparently routing clients trying to access the old URL to the v1 service (instead of having v1 in the root and v2 in it's own folder).
I've tried setting a route in Global.asax:
RouteTable.Routes.MapPageRoute("MyServiceV1", "MyService.svc", "~/v1/MyService.svc");
Also tried setting the service endpoint:
<endpoint address="/MyService.svc"
binding="webHttpBinding"
contract="MyApp.V1.IMyService"
behaviorConfiguration="web" />
Neither of these seemed to work.
Is there any other way to do this?
Was trying to avoid URL rewriting as I was hoping there was a simpler way to achieve this using built in functionality, but this turned out to be the easiest way to resolve the issue.
First I had to install the IIS add-in for URL rewriting. This can be done by downloading URL Rewrite from the Microsoft website, or installing it via Web Platform Installer.
Once that was done, I added the following to web.config in my WCF service web application.
<system.webServer>
<!-- Other stuff here -->
<rewrite>
<rules>
<!-- Rewrite requests to /MyService.svc to /v1/MyService.svc -->
<rule name="MyService v1" stopProcessing="true">
<match url="MyService.svc(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="/v1/MyService.svc{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
This allows the v1 service to be accessed via both /MyService.svc and /v1/MyService.svc, and v2 can be accessed via /v2/MyService.svc.

How to redirect non-existent .html files to mvc3 routes?

This is probably a duplicate, but my Google-foo is off or something, because I cannot find the answer to this simple question.
I have moved an old site to MVC3 on IIS7.5 and I need to redirect some old .html extension urls to new MVC Controller Actions.
I added URL mappings.
<urlMappings>
<!-- Doesn't work -->
<add url="~/OldUrl.html" mappedUrl="~/NewController"/>
<!-- Works but is rewrite instead of redirect -->
<add url="~/OldUrl.aspx" mappedUrl="~/NewController"/>
</urlMappings>
The above is not working for 2 reasons. First, the .html extension doesn't get re-mapped and second, the .aspx extension gets re-mapped rather than rewritten.
I tried to add the StaticFileHandler because I thought maybe the .HTML extension was being ignored by .NET but in fact that handler was already there.
I don't have access to IIS Management Tools because it is in shared hosting, but I should be able to just add something to the web.config to get these to redirect.
Finally figured it out:
<system.webServer>
<!-- The RewriteModule may need to be added if it isn't
already included in machine.config or application.config
<modules>
<add name="RewriteModule" />
</modules>
-->
<rewrite>
<rules>
<rule name="Redirect1">
<match url="^OldUrl.html$" />
<action type="Redirect"
url="/NewController"
redirectType="Permanent" />
</rule>
<rule name="Redirect2">
<match url="^OldUrl.aspx$" />
<action type="Redirect"
url="/NewController"
redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>