System.Webserver rewrite and secure at the same time - asp.net

I'm serving Confluence through IIS to end user, here is web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<security>
<requestFiltering allowDoubleEscaping="True" />
</security>
<rewrite>
<rules>
<rule name="RewriteUserFriendlyURL" stopProcessing="false">
<match url="\+" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{UrlDecode:{REQUEST_URI}}" />
</rule>
<rule name="inbound" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://localhost:8090/{R:1}" />
</rule>
</rules>
</rewrite>
<handlers>
<remove name="WebServiceHandlerFactory-ISAPI-2.0-64" />
<remove name="WebServiceHandlerFactory-ISAPI-2.0" />
<remove name="PageHandlerFactory-ISAPI-2.0" />
<remove name="PageHandlerFactory-ISAPI-2.0-64" />
<remove name="PageHandlerFactory-Integrated" />
<remove name="WebServiceHandlerFactory-Integrated" />
<remove name="SimpleHandlerFactory-ISAPI-2.0-64" />
<remove name="SimpleHandlerFactory-ISAPI-2.0" />
<remove name="SimpleHandlerFactory-Integrated" />
<remove name="CGI-exe" />
<remove name="ISAPI-dll" />
</handlers>
</system.webServer>
</configuration>
Confluence runs in it's own process on port 8090
What I want is somehow add confluence as a subfolder to another site so it goes to:
site.com/confluence
site.com is ASP.NET website. I'd like to password-protect /confluence folder.
So, if user logged in to site.com (ASP.NET Membership provider) - they get access to /confluence folder.
Is this possible and how this should be done?

What you are asking for is Delegated Authentication of a IIS Reverse Proxy.
This is technically possible.
You don't want to do this. Because you would need to use ASP.Net authentication to view the website. But then you also need to log in using your confluence log in.
You actually want to use
IIS Reverse Proxy/Application Request Routing (this puts the Confluence website in the "subfolder")
Single Sign-on Integration with ASP.Net Membership.
https://confluence.atlassian.com/kb/single-sign-on-integration-with-the-atlassian-stack-794495126.html
With this solution, Confluence uses Crowd to connect to ASP.Net using OpenID.
I recommend using IdentityServer to expose your ASP.Net Membership Provider to the OpenID api.

Related

IIS ARR with wordpress not working from internet Error timeout

I have an IIS server in my network with a domain configured who based on some ARR rules on the web.config shows a wordpress that is installed with xaamp in other server in my network.
So when yo go to example.com it shows the wordpress that its in 192.168.110.104:8080
When I try to access to example.com from my network, seems like the rules works fine and the wordpress content it works properly but when I try to access to the domain example.com from the internet it shows a lot of errors as looks like it's trying to load 'internal resources' form internet? obviously it load without css styles, some images works, some not, so it's a mess.
Errors are timeout like this.
GET http://192.168.100.104:8080/wp-content/themes/astra/assets/css/minified/style.min.css?ver=2.4.4 net::ERR_CONNECTION_TIMED_OUT
In the wordpress I have configured the :
wordPress (URL) as http://192.168.100.104:8080
web url : http://192.168.100.104:8080
Maybe I have to place the domain there instead the local ip?
This is my web.config from the IIS
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<add value="homepage.asp" />
</files>
</defaultDocument>
<cors enabled="true" failUnlistedOrigins="true">
<add origin="*">
<allowHeaders allowAllRequestedHeaders="true" />
</add>
</cors>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="{C:1}://192.168.100.104:8080/{R:1}" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
</rule>
</rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img" pattern="^http(s)?://192.168.100.104:8080/(.*)" />
<action type="Rewrite" value="http{R:1}://example.com/{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<staticContent>
<clientCache cacheControlMode="NoControl" />
</staticContent>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET, PUT, POST, DELETE, HEAD, OPTIONS" />
<add name="Access-Control-Allow-Credentials" value="true" />
<add name="Access-Control-Allow-Headers" value="X-Requested-With, origin, content-type, accept" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
Any ideas? thanks in advance!

How to navigate to index.php when instance name is entered in URL section, but block access to files based on extension in Web.config file?

I have requirement where I blocked the access to files based on extension using below lines in Web.config file for IIS.
<system.webServer>
<security>
<requestFiltering>
<fileExtensions allowUnlisted="false">
<add fileExtension=".php" allowed="true" />
<add fileExtension=".js" allowed="true" />
<add fileExtension=".css" allowed="true" />
<add fileExtension=".png" allowed="true" />
<add fileExtension=".jpg" allowed="true" />
<add fileExtension=".gif" allowed="true" />
<add fileExtension=".jar" allowed="true" />
</fileExtensions>
</requestFiltering>
</security>
</system.webServer>
But these lines preventing the application from navigating to index.php (home page). How to resolve this problem?
Follow Lex Li's method would achieve your requirement. Besides, URL rewrite could provide another way to block all unlisted extension based on {PATH_INFO} variable.
<rule name="rewrite" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{PATH_INFO}" pattern="\.(js|php|css|png|jpg|gif|jar)$" negate="true" />
</conditions>
<action type="AbortRequest" />
</rule>

Angular Routing in IIS server

I have an Angular 4 app in a IIS server, in the same server there is a .NET Web API. They are in diferents folders: angular app is in "/wwwroot/angular/" and web api in "/wwwroot/api/". When I do a request to web api, it works successfully, but when I try to navigate to an URL different to index.html using the Routing Module in angular app I get this message:
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
Also, I have two Web.Config files -one in each folder-.
My Angular Web. Config is:
<system.webServer>
<rewrite>
<rules>
<rule name="Angular 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>
Web.config of WEB API
<configuration>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
</configuration>
I researched in some questions like:
stackoverflow.com/questions/49833141/blank-page-when-publishing-angular-5-net-core-web-api
and
stackoverflow.com/questions/42865084/redirect-unknown-requests-to-index-html-in-springboot
But they doesn't work to me.
Anybody help me on this.
Thanks in advance.
The solution was move all the Angular files to root, at index.html I left <base href="/"> and make the web.config like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rewriteMaps>
<rewriteMap name="^(.*)$" />
</rewriteMaps>
<rules>
<rule name="Angular Route" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" pattern="/api(.*)$" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
<security>
<authorization>
<remove users="*" roles="" verbs="" />
<add accessType="Allow" users="?" />
</authorization>
</security>
</system.webServer>
</configuration>
In your web.config change <action type="Rewrite" url="/FIN360" /> and in your index.html from the <base href="/"> remove the / Try this else change <base href="./"> OR <base href="/FIN360">

ASP.NET Core http 500 error

I have created a redirect rule in my web.config in order to redirect my website from http to https. I published my website on my staging and it was working perfectly. After some manipulation in my web.config, i published again my website and now i have a HTTP 500 error. I tried to undo those modification and set my web.config as it was and i still have that error. I tried everything as well as deleting my web.config and create a new one but it seems that the manipulation i did has crushed my staging and i am not able to make it work again.
This is my web.config before redirection:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false">
</aspNetCore>
</system.webServer>
</configuration>
This is what i added for redirecting my http to https and it was working perfectly.
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
Then i made some manipulation and change the action input {HTTP_POST} to my domain name. While it is working locally, my staging is not working anymore and i tried to undo everything but i still have the HTTP 500. What should i do?

How to Configure UrlRewritingNet on the server side IIS 7 Windows 7 Server

I have finished an ASP.NET web site after making tests.
I am using UrlRewritingNet dll from http://www.urlrewriting.net/
Then I have published it in order to upload my server (Windows 7, IIS 7 installed). After typing my site's URL I get 404 - Not found error. This is because of missing or bad configuration on the server side. But I do not know what to do exactly.
Searched many times but could not find anything close to my problem.
For a last chance I am here. Can you help?
You can see my web.config content in the following:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<section name="urlrewritingnet" requirePermission="false" type="UrlRewritingNet.Configuration.UrlRewriteSection, UrlRewritingNet.UrlRewriter"/>
</configSections>
<system.web>
<httpModules>
<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter"/>
</httpModules>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<handlers>
<remove name="PageHandlerFactory-ISAPI-4.0_32bit"/>
<add name="PageHandlerFactory-ISAPI-4.0_32bit" path="*.aspx" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0"/>
<add name="reww" path="*" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="None" preCondition="classicMode,runtimeVersionv4.0,bitness32"/>
<add name="rewwibu" path="*.ibu" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv4.0,bitness32"/>
</handlers>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
<urlrewritingnet configSource="ExternalRewrite.config"/>
</configuration>
This is my new Web.Config File:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false" />
<rewrite>
<rules>
<rule name="GoAnasayfa">
<match url="^([_0-9a-z-]+)/Anasayfa.ibu" ignoreCase="false" />
<action type="Rewrite" url="Default.aspx?lang={R:1}" appendQueryString="false" />
</rule>
<rule name="GoIletisim">
<match url="^([_0-9a-z-]+)/Iletisim.ibu" ignoreCase="false" />
<action type="Rewrite" url="Contact.aspx?lang={R:1}" />
</rule>
<rule name="GoDereceProgramlari">
<match url="^([_0-9a-z-]+)/DereceProgramlari/([_0-9a-z-]+).ibu" ignoreCase="false" />
<action type="Rewrite" url="DegreePrograms.aspx?lang={R:1}&derece={R:2}" />
</rule>
<rule name="GoOgrenci">
<match url="^([_0-9a-z-]+)/Ogrenci.ibu" ignoreCase="false" />
<action type="Rewrite" url="Ogrenci.aspx?lang={R:1}" />
</rule>
<rule name="GoKatalog">
<match url="^([_0-9a-z-]+)/([0-9]+)/([0-9]+)/([0-9])/Katalog.ibu" ignoreCase="false" />
<action type="Rewrite" url="Catalog.aspx?lang={R:1}&opID={R:2}&pmID={R:3}&oid={R:4}" />
</rule>
<rule name="GoDersDetay">
<match url="^([_0-9a-z-]+)/([0-9]+)/([0-9]+)/([0-9])/([0-9])/DersAyrintilari.ibu" ignoreCase="false" />
<action type="Rewrite" url="CourseDetail.aspx?lang={R:1}&opID={R:2}&pmID={R:3}&DersID={R:4}&dersKodu={R:5}" />
</rule>
<rule name="GoLLPKoordinatorleri">
<match url="^([_0-9a-z-]+)/LLPKoordinatorleri.ibu" ignoreCase="false" />
<action type="Rewrite" url="Coordinators.aspx?lang={R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
When I type my web adress the address bar is filled with lang parameter like below:
http://somedomain.com/tr-TR/Anasayfa.ibu?lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr....
and then browser shows an error message:
Invalid Redirect URL
Try to add:
<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter"/>
<remove name="Session"/>
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
to your web.config under
<configuration>
...
<system.webServer>
...
<modules>
<!-- add here -->
</modules>
</system.webServer>
...
</configuration>
Why not use the URL rewrite module from Microsoft?
http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module
Be sure to install the correct version based on your system's setup. Then you can proceed with creating your rewrite rules as demonstrated here:
http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module

Resources