Blazor Wasm in subfolder - iis

I have two blazor wasm applications I would like to host withing the same root folder as follows:
MainSite
     |_ Customers
Each of those are seperate applications.
Is it possible to host the 'customers' wasm site within the same 'root' folder but treat it as completely seperate application? i.e.
http://localhost:8999/ (takes you to -> Root Site)
http://localhost:8999/Customers (takes you to -> /Customers)
I have tried to to the following without any luck:
a) modified <base href="/" /> to <base href="/customers/" /> for subfolder 'customers' application
b) added some url rewrite rules in 'customers/web.config'
<rewrite>
<rules>
<rule name="ExampleToDemo">
<match url="^(.*)customers" />
<action type="Rewrite" url="^(.*)customers\wwwroot\{R:0}" />
</rule>
<rule name="SPA fallback routing 2" stopProcessing="true">
<match url="^(.*)customers" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="customers\wwroot\" />
</rule>
</rules>
</rewrite>
Root site works as expected:
Sub directory 'Customers' shows this:
Instead of this:
How can I make the sub dir customers site work using the /customers path?

Related

IIS Rewrite Module and sub applications / React-Router

Ok, this is similar to other questions out there but I am not familiar with url rewrite.
I am hosting (hopefully only for development and testing) a react application under IIS.
If hosted in the root of the site folder all is well using
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Static Assets" stopProcessing="true">
<match url="([\S]+[.](svg|js|css|png|gif|jpg|jpeg))" />
<action type="Rewrite" url="{R:1}" />
</rule>
<rule name="ReactRouter Routes" 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="/index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
But I need it to work in a subapplication. For instance: http://myserver:8888/myapp. Where myapp is the sub application.
IIS diagram:
Sites
- MySite
- MyApp
Better example of the url that includes the route: http://myserver:8888/myapp/1234/abcd.
1234 and abcd are route values/params.
contents of my app directory are:
index.html
main.a9e1df0325f4fdb57e7e.js
vendors~main.c8848853e10f698af19d.js
web.config
Thanks
Gina
You could host your app in any subapplication in iis but be careful to defining correct route for serving contents. It seems you want to host static content so you can't use route parameters in url hence these parameters are used by asp.net. Static content are served by iis. You can try this url for serving content in myapp:
http://myserver:8888/myapp/index.html

IIS Rewrite IP:Port to {domain}/{thing}

What I'm trying to do:
I own a domain, let's say blahblahblah.com
On the server, it points to :80 and :443 properly - this is working
I want to remap so that if a user visits blahblahblah.com/thing1 then it maps to localhost:5000
Similarly, I also want to remap so that if a user visits blahblahblah.com/thing2 then it maps to another server and port on my local network (not exposed to the internet)
I essentially want to use my webserver to communicate with other servers on my network and other ports through "sub directories" or whatever they are called in this instance (site/subdir, site2/subdir). I've been trying to solve this issue for days! I've installed ARR (and enabled the Proxy) and the URL Rewrite modules on my IIS.
I've attempted god knows how many different rewrite templates on SO. I can get partial success, in which the route /thingx/ resolves, but all the resources are referencing blahblahblah.com and (appropriately) can't find the resources for the site at that address.
Current rewrite (resolves some resources at blahblahblah.com/thing1, but others are misrouted):
<rewrite>
<rules>
<rule name="Thing1" enabled="true">
<match url="(thing1*)" />
<action type="Rewrite" url="http://localhost:5000/{R:0}" />
</rule>
</rules>
</rewrite>
EDIT: I've updated my rules to the below, as per this article from Microsoft Docs: Reverse Proxy with URL Rewrite v2 and Application Request Routing . These rewrites supposedly do exactly what I need, but the result is not the same in my case, and I still have no clue why.
<rules>
<rule name="Thing1" enabled="true">
<match url="^thing1/(.*)" />
<action type="Rewrite" url="https://localhost:5000/{R:0}" />
</rule>
</rules>
<outboundRules>
<rule name="Add application prefix" preCondition="IsHTML">
<match filterByTags="A" pattern="^/(.*)" />
<conditions>
<add input="{URL}" pattern="^/(thing1)/.*" />
</conditions>
<action type="Rewrite" value="/{C:1}/{R:1}" />
</rule>
<preConditions>
<preCondition name="IsHTML">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
More Notes:
localhost:5000 works as expected
localhost/thing1 resolves in 404 Not Found
blahblahblah.com/thing1 resolves in pulling in the default HTML page, but none of the assets (javascript, css, etc), they return 404 Not Found.
EDIT: It may be important to note that these rules have been written into the default site (bound to :80, :443) on IIS' web.config. Writing these rules in C:\Windows\System32\inetsrv\config\applicationHost.config results in a 500.
Any feedback on what I'm doing wrong?
Part of this was due to the way SPAs are handled (# and history mode), but I ended up solving with the below webconfig for IIS, which allows me to nest everything under a /foobar endpoint:
<rewrite>
<rules>
<rule name="Subdirectory Index" stopProcessing="true">
<match url="^foobar/index\.html$" ignoreCase="false" />
<action type="None" />
</rule>
<rule name="Subdirectory Routes" stopProcessing="true">
<match url="." ignoreCase="false" />
<conditions>
<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="/foobar/index.html" />
</rule>
</rules>
</rewrite>

Rewrite URL for path to domain in Azure App Service using Virtual Directory

I have set up an Azure App Service to use Virtual Directories.
The path my-app.azurewebsites.net/api is working correctly with the site wwwroot/api.
I have a CNAME record for api.mydomain.com to my-app.azurewebsites.net which works just fine as well. I can successfully call api.mydomain.com/api.
However I'd like to use a subdomain instead of the path, rewriting api.mydomain.com to api.mydomain.com/api
I've added a web.config file in my wwwroot directory which looks like following now
wwwroot/
- api/
- web.config
web.config:
<rewrite>
<rules>
<rule name="My redirection">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^api.mydomain.com$" />
</conditions>
<action type="Redirect" url="https://api.mydomain.com/api/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
After a restart, the App Service is not responsive and does not serve requests anymore. Is there a better way to achieve this or do I need to modify my rewrite?
After a few attempts I figured the mistake. Redirect has to be changed into Rewrite.
<rewrite>
<rules>
<rule name="My redirection">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="api.mydomain.com$" />
</conditions>
<action type="Rewrite" url="api/{R:1}" />
</rule>
</rules>
</rewrite>

Creating subdomains in Azure

We have a VM in Azure, ourserver.westeurope.cloudapp.azure.com. I need to create two subdomains, sub1.ourserver.westeurope.cloudapp.azure.com and sub2.ourserver.westeurope.cloudapp.azure.com. Both must point to the same IP as ourserver.westeurope.cloudapp.azure.com.
How do I do it?
For now, Azure does not support add subdomains.
If you want to use subdomains, maybe you can buy a domain name from domain register(third party, like register.com, godaddy.com), and map your domain name to this VM's Public IP address, then add subdomains to this public IP address.
You can also use different port numbers for each website.
Default port: 80 ourserver.westeurope.cloudapp.azure.com
Port: 8081 sub1
Port: 8082 sub2
and Etc.
To access Go to:
http://ourserver.westeurope.cloudapp.azure.com:portNumber
http://ourserver.westeurope.cloudapp.azure.com:8081 ---> sub1
I'm not sure, but MAYBE, the URL rewrite can work in this situation.
You can have different folders inside you VM's "public" folder, one for each content of the subdomain. Then, use the URL Rewrite to map each subdmain in their specific folder.
I did something similar, but wasn't for subdomains. I just pointed different domains to different folders. Here is an example of how it would be in your case (I didn't test, just guessed based on my case):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="sub1 virtual path rewrite">
<match url="^.*$" ignoreCase="false" />
<conditions>
<add input="{HTTP_HOST}" pattern="^sub1\.ourserver\.westeurope\.cloudapp\.azure$" />
</conditions>
<action type="Rewrite" url="/Sub1Folder/{R:0}" appendQueryString="true" />
</rule>
<rule name="sub2 virtual path rewrite">
<match url="^.*$" ignoreCase="false" />
<conditions>
<add input="{HTTP_HOST}" pattern="^sub2\.ourserver\.westeurope\.cloudapp\.azure$" />
</conditions>
<action type="Rewrite" url="/Sub2Folder/{R:0}" appendQueryString="true" />
</rule>
</rules>
<outboundRules>
<rule name="sub1 virtual path rewrite">
<match serverVariable="RESPONSE_LOCATION" pattern="^(https?\://ourserver\.westeurope\.cloudapp\.azure)/Sub1Folder/(.+/)$" />
<conditions>
<add input="{RESPONSE_STATUS}" pattern="^301$" ignoreCase="false" />
</conditions>
<action type="Rewrite" value="sub1/{R:1}/{R:2}" />
</rule>
<rule name="sub2 virtual path rewrite">
<match serverVariable="RESPONSE_LOCATION" pattern="^(https?\://ourserver\.westeurope\.cloudapp\.azure)/Sub2Folder/(.+/)$" />
<conditions>
<add input="{RESPONSE_STATUS}" pattern="^301$" ignoreCase="false" />
</conditions>
<action type="Rewrite" value="sub2/{R:1}/{R:2}" />
</rule>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
I don't know if you will need to create subdomains in the domain register. Maybe you will need to, because sometimes you have to pay extra fees to have subdomains.
So, I don't know if the URL Rewrite would work without creating them. And if it works, I don't know if it's legal to do (please don't do any workaround to avoid the register fees).

redirect user in IIS7 between two folders depending on IP mask

Suppose I have Default Web Site and folders in it.
Roughly, the tree would look like this:
|- Server
|- Default Web Site
|- folder1
|- folder2
I want to redirect the user to different folders in my website depending on their IP mask.
For example if the user's IP has a pattern of:
- 10.10.10.* IIS has to redirect to "folder1"
- 11.11.11.* IIS has to redirect to "folder2"
Is this possible? If so, then how?
<rule name="RedirectBySourceIP1" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{REMOTE_ADDR}" pattern="10.10.10.(.*)" />
<add input="{URL}" pattern="folder1(.*)" negate="true" />
</conditions>
<action type="Redirect" url="/folder1" />
</rule>
<rule name="RedirectBySourceIP2" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{REMOTE_ADDR}" pattern="11.11.11.(.*)" />
<add input="{URL}" pattern="folder2(.*)" negate="true" />
</conditions>
<action type="Redirect" url="/folder2" />
</rule>

Resources