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.
Related
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!
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.
I have
www.mydomain.com -> SPA app
and
www.mydomain.com/api -> NET core Rest Api
Both are hosted on separated IIs Applications, and I added a web.config on my Vuejs app to allow my setup to work :
<rewrite>
<rules>
<rule name="Handle History Mode and custom 404/500" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_URL}" pattern="^/api/(.+)" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.html" />
</rule>
</rules>
</rewrite>
All working fine until I implemented a custom OAuth provider on my Net Core app like that one : https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers/tree/dev/src/AspNet.Security.OAuth.Apple
So I configured my CallbackPath to "/start", so it should generate:
redirect_uri=www.mydomain.com/start
but it generate
redirect_uri=www.mydomain.com/api/start
I know why its happening, but I dont know how can I force redirect_uri to not use /api
Is it possible to change that? Or should I try to host both APP on same IIS application?
Thanks
I have asp.net core application. It works well but we are going to use https then. What I have to do?
Steps in local development and in production?
For example, in local the url is http://localhost:12345; but we want https://localhost:12345
update:
In production I am talking about hosting in IIS
In local development, you don't have to change anything if you're using IIS to expose your service.
In IIS either
check 'require SSL' for your site under 'SSL settings'
or if you want to redirect http traffic to https; do NOT check 'require SSL', but add a redirect rule
Like so
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
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>