ASP.NET routes on IIS 7 keep reverting - asp.net

I have deployed an ASP.NET MVC web application to an IIS 7 server. It's in the root directory of the www folder. There is a sub folder that is not part of the application that needs to be served up as normal. So I added some code into my MVC app routes.
Basically I:
routes.IgnoreRoute(name);
var ignore_route = string.Concat(name, #"\/(.*)");
routes.IgnoreRoute("{*path}", new { path = ignore_route });
This words perfectly. For a while. Then it breaks. Specifically, going to "/subDirectory" (i.e. without the trailing slash) gives a "401 - Unauthorized: Access is denied due to invalid credentials." This wouldn't bother me except for the fact that due to business cards in the wild giving the subDirectory url without the trailing slash. It has to work.
It always works fine on my dev machine, but it's not running on IIS there.
I don't understand how it could work for a while and then break. If I copy over the assembly, it starts working again, and then it stops by the next day.
One possibility is that when I first deployed this web application, this code was not present. I had to add it later when we realized that there needed to be subdirectories that would be served up normally. So my first gut feeling was that it was somehow reverting back to an older version of the assembly. I have no idea how this would happening, though. When I access the directory via ftp, the modified dates are correct. The only access I have to the server is through ftp, but the server admins who are supposed to be helping me with this have been frustratingly absent. I'm at my wits end. Any ideas?
EDIT: I don't know why this was sent over here to stack overflow. This is obviously a server issue, isn't it? Look at the first response! It's talking about the server. The code works fine. Can we get this booted back over to serverfault where it belongs?

May be your server rebooting the HttpApplication once in a while and you're checking a boolean to see whether it's configured or not which stays true, so you don't add routes?

Related

How do I find where a redirect is occurring on my website

We're moving an instance of a third party, .NET-based website to a Win2016 server, IIS 8, from an external hosting service. Under the site, there's a WCF web service in a subfolder. There are no virtual directories or apps.
mysite.../Order/v4/service.svc
When I browse to pull the wsdl (https://MySite.../Order/v4/Service.svc?wsdl ), it is redirecting to Login.aspx (https://MySite.../Order/v4/Login.aspx).
Browsing to https://MySite/Order/v4/Service.svc?wsdl redirects to https://MySite/Order/v4/Login.aspx .
IIS has no default document set / web.config's defaultDocument is commented out.
Vendor indicates
That would be a redirect that was setup either on IIS or another
appliance that is doing that.
Same behavior occurs running on the server itself (localhost) and sys eng confirms it shouldn't be leaving the network to hit any firewall.
There are no other .config files on the server with any reference to "Login.aspx".
This still feels like it is some piece of configuration but even doing things I shouldn't need to do like restarting the server just to make sure no caching of settings is hanging around isn't affecting it.
Any guesses on what might be attempting to redirect?
Following Rich-Lang's suggestion in comments provided the information to identify that the global.asax file was handling an error in the web.config. Since the code in this case was in codebehind in a dll, and the vendor indicated their code does not redirect, I had not seen that culprit before. Removing the global.asax and turning off customErrors allowed me to see the underlying issue.

set Default.html as start page in Web application

I had played down with my host configurations to the point that I can't revert back! I just want to be able to run it from my own visual studio, so I can debug some javascript and don't care if it is not running on Local IIS. I have web application in VS 2013 (Proj1) that I want to add a default.html page to. I set it as the start page, but when running the app, I keep getting the error:
HTTP Error 500.19 - Internal Server Error The requested page cannot be
accessed because the related configuration data for the page is
invalid.
Luckily, this is my own personal machine and I don't mind resetting its IIS or changing its apps configurations. I've tried the following:
I had initially setup my web application via VS as SSL Enabled = true, but now I am trying to reset, so my project properties look like this:
Even though I don't care about IIS setup, I still looked into my C:\Windows\System32\inetsrv\Config\applicationHost.config file, but looked fine
looked at my web.config, but nothing stands out
I think the process of setting up the SSL is the culprit. Is there anywhere else I should look? I just want to be able to run a simple Default.html
I had a problem very similar to this before in the past. This is what I did to solve it.
Try to debug a very basic page with nothing on it (Make sure that works)
Then start building the page back up.
For me it was when I added "Custom Controls" back in, when I removed those controls from the page everything worked.

MVC error 403 - Forbidden: Access is denied. Works locally but not remotely

Deployed an MVC5 site on IIS7.5 and receive this error when trying to access remotely:
403 - Forbidden: Access is denied.
From the server itself, I do not receive the error.
I tried the common suggested fixes like adding
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
to web.config, and running aspnet_regiis for version 4.0.30319, but nothing works.
Months back I had deployed another MVC site (though it was MVC version 3), and it is up and running, without this nonsense. I can't remember exactly what was done to successfully deploy, but I don't recall headaches like this. Just out of speculation this wasn't due simply to the newer version of MVC, I copied and pasted the folder of the working MVC3 web app, converted it to an application through IIS, used same app pool, and... receive the remote 403 error on it. So with an exact copy giving a 403, while the app that I copied works fine, tells me there's some IIS setting I might be missing? Obviously the web.configs are exactly the same. Folder permissions look the same. I put a test html page inside the web app folder, and I can access that through a browser remotely. I don't know, I don't spend too much time in IIS configuration hell, and it's frustrating beyond belief. If anyone has any ideas...
Since you said that it worked locally the issue must be here:
Check your App_Start/BundleConfig.cs file for css references which match the physical folder path of the project.
Here is an example:
bundles.Add(new StyleBundle("~/Content/bootstrap").Include("~/Content/bootstrap/less/bootstrap.css"));
As you can see, /Content/bootstrap is also a folder path. What you have to do is, rename this style bundle to something else. Say, "~/Content/bootstrap-css". Basically, it shouldn't match a physical folder path.
I had this problem, it works locally but not on the server. So, it should help!
Cheers!
Check the Basic Settings for your domain in IIS. Set it to DefaultAppPool. This resolved the same issue for me.

Getting 404 error in IIS when calling asp page

I have a problem with my asp.net 4.0 application. When I call it on the server, it works, but when I call it from outside the server, it gives me a 404 error.
The link I call the asp.net application from is the good one. Other asp.net 4.0 applications are working fine when called from outside the server. The other applications are in another folder though, but I do not see why it would work under a folder and not another one. There is no IP restrictions on the applications.
Anyone got that error int eh past?
Thanks
EDIT:
The app is configured as an asp.net 4.0 application. it is stored in a virtual directory.
This link works:
http://localhost/Phonebook/PhoneBook/default-defaut.aspx
this link does not : https://www.test.com/Phonebook/PhoneBook/default-defaut.aspx
A coworker and me found the answer. It's because the server I called on my url was supposed to have a rule redirecting the browser to the right url. So IIS7 on my test server was setted up right.
Theres several things to check.
That test.com is even going to your server. Put a file in the root directory 'test.txt' that IIS lists as the root folder for your site. ensure you can get to it.
Once you verify your root site folder WORKS for ex., www.test.com/test.txt then ensure you have a virtual directory /phonebook that contains a folder phonebook within it.
Seems overkill to be having to folders named phonebook. Try taking one of them out and pointing your web application to your
c:\whatever\phonebook\phonebook folder.
Make sure port 443 is bound to your app if you're using https, that could be your problem.

ASP.NET: Errors not viewable despite proper configuration

I'm having the classic (dare I say typical?) error on the ASP.NET production server, which tells me that I can't view errors. Below the error displayed below, are things I've already tried.
In IIS Manager (6.0), the application is located under one of the web sites in "Web Sites". It is indeed a web application, as opposed to a virtual directory (it has that gear icon).
When trying to view the error from the localhost (i.e. the server itself), it doesn't find the application on its path, even though the root web site works just fine from localhost. It is clearly not a firewall issue because first of all, the firewall is turned off, and second because the root web site works fine from localhost. Heck, I even tried connecting through telnet and that worked fine and dandy too, so it is most certainly and very clearly not a firewall issue.
Basically, I just need to view the error at all. I won't have to fix this problem if I can just see the error and fix it, because obviously there is something wrong in the code itself... I just don't know what, because IIS/.NET won't tell me.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a tag within a "web.config" configuration file located in the root directory of the current web application. This tag should then have its "mode" attribute set to "Off".
So what I've already tried is what the error message itself suggests by setting the customErrors thing to "Off". In fact, it always was on "Off" so I didn't have to change anything. I've made sure that the web.config XML is valid.
Another common reason for this error is that the .NET run-time is set to version 1.1, not 2.0. I've also made sure that this is correctly configured to 2.0.
I'm running it in an independent application pool, meaning that there are no other applications at all, much less 1.1 applications, on the same application pool.
I've made sure that EVERYONE can do ANYTHING to the files and directories in the application itself. I understand the security ramifications here, I'm just trying to get it working at all, and then I'll constrain the access rights afterward, one step at a time. But in any case, everyone can read those files.
Any help deeply appreciated. Thank you in advance.
The error is a .NET framework error so it finds the app, but there is a configuration error. What you could do is add some event logging code in APplication_Error handler in global.asax to trap these errors, or turn on health monitoring (<healthMonitoring enabled="true" />), which by default will log ASP.NET framework errors to the event log.
HTH.
Never got this working until I changed the application from a "sub-application" (I don't know the proper terminology) to an independent website with its own hostname. ASP.NET works in mysterious ways.

Resources