Recycling the Application Pool creates 401 errors - iis-7

I am using the Rewrite Module on IIS 7.
When I restart the Application Pool I get a Authentication Required window that doesn't except any credentials that it is given and when you click cancel it goes to a 401 unauthorized page.
The rewrite rule sends the request to an ashx page in a virtual directory (_assets).
How can I resolve this strange behavior?
Anonymous is turned on and it works fine.
The following is the rewrite rule we are using:
<rewrite>
<rules>
<rule name="Loader" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^[a-z0-9\-\/]*$" negate="false" />
<action type="Rewrite" url="/_assets/includes/load.ashx?q={UrlEncode:{REQUEST_URI}}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
I can get past the weird login by going to /.reset. This causes a 500 error and then the site is available again.
Note: Our application pools restart nightly.

I found a forum post that outlines a problem pretty similar to yours (it also outlines how they managed to fix it). Hopefully it helps you sort out the issue!

Related

IIS URL HTTP to HTTPS redirect not working on ASP.Net application

I have an ASP.Net application being hosted on a webserver with Plesk installed.
The application is hosted on a sub-domain (webapp.website.com) and the link to login to the system is supplied through the main domain website, so I haven't noticed this up until now.
If you type in webapp.website.com or http://webapp.website.com the website will connect to an unsecured page with the following error:
Server Error
403 - Forbidden: Access is denied.
You do not have permission to view this directory or page using the credentials that you supplied.
If you manually type in https://webapp.website.com (which is what the link is setup to do) the app connects just fine and works as expected.
I have enabled Permanent Redirect to HTTPS in Plesk, and have manually written a redirect rule in IIS Manager, but for some reason it seems to be ignoring this rule because the server connection is failing in HTTP and displaying the Server Error page instead.
How can I resolve the redirect issue to either stop the error on HTTP, or for it to skip over and redirect to HTTPS?
I suspect there may be a problem with your rules, you can try the following rules:
<rewrite>
<rules>
<rule name="Test" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="OFF" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
This rule will redirect all http requests to https.

IIS 7.5 404 not found for all images via one of the http bindings

I have ASP.NET MVC site on IIS 7.5/Windows Server 2008 R2. Site have a set of http bindings to different domains, such as domain1.test.dev.com. domain2.test.dev.com, 10 bindings in total. They all are doing well, except one. Every request for an image(jpg, gif, png) returns 404 for this single binding. So entire layout has been loaded, all others requests feel good, but all images are broken with error 404 Not Found. There are no https bindings, they all are using http, port 80 and IP Address is 'All Unassigned'.
Could anyone help please?
The answer is found. There was an additional web.config file in ~/Images directory. This config contained specific redirection rule for one of the domain, so for this domain I saw 404, and others worked great. An additional web.config appeared in ~/Images directory accidentally, because of missclicking
in URL Rewrite module on the IIS. Some time ago we have used such redirections for demo and removed them after that. The redirection rule in web.config was a kind of:
<system.webServer>
<rewrite>
<rules>
<rule name="ProductionRedirectDomain1" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{CACHE_URL}" pattern="*domain1.test.dev.com*" />
</conditions>
<action type="Redirect" url="{C:1}domain1.com{C:2}" />
</rule>
</rewrite>
</system.webServer>
The bug has disappeared after removing a redundant config. Thanks, everybody!

web.config redirect not working on localhost

I have a website that I work on in visual studio and then deploy to azure. I'd like to create a permanent redirect in my web.config file. I would like to test this to make sure it works before I deploy to azure.
Here is my web.config file
<rewrite>
<rules>
<rule name="301Redirect" stopProcessing="true">
<match url=".*/PEOs.aspx" />
<action type="Redirect" url="http://myblogpost.com" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
So when the user visits www.mysite.com/PEOs.aspx they will be directed to my blog post. The problem is, when I test this, it just goes to the page. Doesn't redirect. I realize I could just write some code in the code behind file, but I want something that's more SEO friendly.
Am I doing something wrong here? I'm fairly certain regex can be used here. But when I replaced it with http://localhost:21537/PEOs.aspx it doesn't work either. I don't want to publish to azure unless I know that this will only be an issue during local testing.
Try using: <match url="PEOs.aspx" />
I was not entirely sure so I checked it here: https://support.rackspace.com/how-to/rewrite-urls-from-aspnet-on-cloud-sites/

IIS URL Rewrite : 403 - Forbidden: Access is denied

I installed IIS URL Rewrite 2.0 and add a rule to redirect all http links to https. Here is my Web.Config Code:
<rewrite>
<rules>
<rule name="REdirect To HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
Everything looks fine. But when I access my website using http, it throws 403 error.
403 - Forbidden: Access is denied.
You do not have permission to view this directory or page using the credentials that you supplied.
TLS 1.0 is enabled with IIS 7.5.
Where I can get more info on exactly what type of 403 error it is?
SSL was enabled in IIS. I just read somewhere that in SSL Settings Require SSL need to be unchecked when using URL Rewrite 2.0.
I deselect the Require SSL and click Apply. Its working fine now.
I was getting the same error; here was my solution, in case it helps others.
My rule was rewriting URLs coming in to the Default Web Site's root application ("/") to "/public", but I was getting a 403 error. The "/public" application worked fine if I requested it directly, and it also worked fine if I disabled the rewrite rule, so permissions there were not the issue.
"Require SSL" was not checked, as noted in an earlier answer.
Looking at the IIS log file, I found that the specific flavor of error was 403.18 - "Cannot execute requested URL in the current application pool".
The web site's root application needs to be assigned the same application pool as the application you're sending the request to.
Its not sure if this will help but I see your rule is not enabled
<rule name="Redirect to https" enabled="false" stopProcessing="true">

IIS Reverse Proxy

I've got two websites.
XX.XX.XX.XXX:5917 which is a webforms website
And
XX.XX.XX.XXX:5916 which is an mvc website.
Both websites on the same IIS 7 server. I can navigate each website, login, etc.
However, when a user goes to XX.XX.XX.XXX:5917/Report I want the content from XX.XX.XX.XXX:5916/Report to be served up, but the url to remain XX.XX.XX.XXX:5917/Report.
To do this, I'm trying to set up a reverse proxy on the 5917 site to serve up content from 5916.
When I have a redirect rule in place, I can click a link in 5917 to Reports and it will take me to 5916/Reports. This works, but changes the address bar. When I use the Rewrite rule option, absolutely nothing discernible happens. If I screw up the end url in the action bracket then the page will break, so I know it's at least evaluating the rule.
Here is the 'working' redirect rule:
<rule name="Reverse Proxy to Reports" stopProcessing="true">
<match url="\bReport\b" />
<action type="Redirect" url="http://XX.XX.XX.XXX:5916/{R:0}" />
</rule>
Am I missing anything? Where do I go from here?
Try adding this on your XX.XX.XX.XXX:5917 WebForms web.config:
<system.webServer>
...
<rewrite>
...
<rules>
<rule name="ReverseProxyInboundRuleForReports" stopProcessing="true">
<match url="(Report/.*)" />
<action type="Rewrite" url="http://localhost:5916/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
You might need 'Application Request Routing' extension on IIS for it to work though. If so then you can get it from this link:
http://www.iis.net/downloads/microsoft/application-request-routing
You can also read more about the technique on this link:
http://weblogs.asp.net/owscott/creating-a-reverse-proxy-with-url-rewrite-for-iis
Good luck!

Resources