Where is defined MVC 4 WebApi custom errors when deployed? - asp.net-mvc

Here is the thing, when I deploy the SAME PACKAGE (copy and paste) with the same Web.config to my local IIS and to the production server IIS i get two different responses when occur errors in the application.
in my local IIS:
{
"Message":"An error has occurred.",
"ExceptionMessage":"The method or operation is not implemented.",
"ExceptionType":"System.NotImplementedException",
"StackTrace":" at AppCenter.Web.Controllers.ApplicantsController.d__a.MoveNext() in e:\\Sample.Web\\Controllers\\HomeController.cs:line 86"
}
in the prod server IIS:
{"Message":"An error has occurred."}
I would like to know where is the configuration that makes it happen, for example, i would like the server to show the stack trace. The Web.config (where I though would be the place for that) is the same in both, so I think that it is somewhere else.
How can I do that?

The property IncludeErrorDetailPolicy on HttpConfiguration controls this information. As you can imagine, the behavior which you are noticing is deliberate so as to not expose too much information which probably could cause a security issue. If you would want a the config file to drive this setting, you could read it yourself and set this policy when webapi configuration is being setup.

Related

Application_Start not firing in ASP.NET MVC app

I've got an ASP.NET MVC app where the Application_Start event appears to not be firing. The symptoms are that an NLog log statement in that handler does not generate a log entry, and none of my routes get populated (so all my requests for controller actions return a 404).
Static files on the server (eg, favicon.ico) are served correctly.
I have log statements in Application_BeginRequest and Application_EndRequest. Those do generate log entries, both for the controller methods and the static files, so I feel pretty confident the app pool is configured correctly.
The problem shows up on our staging server, but not my local machine or our dev server.
Any idea what would cause this?
It ended up being a combination of things. The root cause was inconsistent versions of DLL's, and I solved that by configuring the project to copy the problem assemblies to my bin folder. On top of that, there was some code in Application_Error that was preventing the actual exception from being shown.

Deploying ASP MVC 5 App with IIS 7.5

I try to deploy ASP MVC 5 app in virtual directory (without creating new iis application)
I use IIS 7.5
I already put
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true" />
in web.config file.
But when i go to app url with IE browser it shows me just directory listing like in screenshot below
Is there a way to deploy MVC 5 in virtual directory and make it work like usual MVC application?
You need to convert the virtual directory to application. Right click on it in the IIS management console and choose Convert To Application.... Also make sure that the associated application is configured to use Integrated Pipeline Mode.
I solved this problem earlier in my production environment by checking the directory pointer in IIS. Apparently when I unzipped the deployed site from one server to the next, the zip utility made an extra level, so IIS was pointing to /MyProject when the files were in /MyProject/MyProject. I had a little better clue though, you have Document Browsing enabled based on that screen shot, make sure not to do that in production. I set the site to log custom errors and got a 403.14 response, from there found a blog on my mistake. You need to setup the environment to find the specific module that's failing, I think something to do with trace routes, idk. I'm a software developer that always gets forced into doing devOps; was googling my own problem and thought I'd throw you a line. Without a specific error message, all I can tell you is IIS is not connecting to .NET; something is not configured correctly. Turn off directory browsing, google how to get good error logs back, and let us know the status code so we can help you: 403.14, 401, 500, 404? Also give us the module that's failing. If it's the last one on the handler list, guess what, IIS isn't connecting to the app, which I suspect is your case.

Using ELMAH in medium trust

I'm building an ASP.net mvc app, and am having some problems getting ELMAH deployed using xml logging to a medium trust server, though it works fine on my local machine. It keeps getting a 404 error.
The problem might be that the host doesn't allow relative filepaths, so the "~/App_Data" doesn't work for logging. I switched that to:
logPath="\\Something\Something\ID\www.website.com\web\content\App_Data"
in the web.config. The syntax might be completely off, but I've tried a few variations and none of them worked.
I subsequently found this question and added the recommended code to my web.config, but still no luck. Does anyone know how to get ELMAH to work on medium trust?
Thanks!
The asp.net worker process (or the aspnet user) has minimum rights to write into the filesystem. Try a place like c:\temp where everybody can write files. After this check and set access rights for aspnet user.
It turned out that the ELMAH.dll was calling SQLite, which isn't allowed under medium trust, and was causing ELMAH to fail when deployed to medium trust. I needed to download the source code for ELMAH and re-build it without the reference to SQLite. It is now working. Yay!

Publish ASP.NET MVC Application : read configuration file permissions

I am having some trouble when publishing an MVC application to a server, and even to my personal computer.
The server has the MVC framework installed so that is not the problem, and I also have it installed obviously.
The problem on my local machine is obviously a permissions thing but im not sure what permissions are needed... I tried adding IUSR to the application itself.
The iis error message is:
Module IIS Web Core
Notification BeginRequest
Handler Not yet determined
Error Code 0x80070005
Config Error Cannot read configuration file due to insufficient permissions
Config File ~\Visual Studio 2008\Project\MVCApp\web.config
and on the server im getting "The page cannot be found" when trying to view anything in the app.
also this is a forms auth app that denys everything but authenticated users
You need to have wildcard mappings turned on so that it can resolve the routes.
Take a look at option 1:
http://blog.codeville.net/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/
Basically, IIS is trying to locate a file at the given URL, but it doesn't exist because they are MVC Routes. You need to tell IIS to hand off the request to the ASP.Net route handler, and not to worry about checking if the file exists on the file system. (it will never exist)
I found out that upgrading an MVC 2 project to MVC 3 resulted in the sam error as described above:
Module IIS Web Core Notification BeginRequest Handler Not yet determined Error Code 0x80070005 Config Error Cannot read configuration file due to insufficient permissions Config File ~\Visual Studio 2010\Project\MVCApp\web.config
What solved the problem for me was to delete the Virtual Directory for the project in my localhost IIS, and then clean and rebuild the project.
NOTE! This was an MVC2 project in VS2010 - not VS2008.

Internal Server Error due to config lockdown when deploying my ASP.NET MVC app to my web host

I'm developing an ASP.NET MVC website on a local Windows Server 2008/IIS7 machine and am I'm now attempting to deploy it to my web host provider, ASPnix. I'm using their Shared Web Hosting service and have been placed on an IIS7 server which they claim supports ASP.NET MVC.
However, when I deploy the application up to their servers, I get an "Internal Server Error".
Here's the Error Summary:
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Here are the relevant portions of the Detailed Error Information:
Module: IIS Web Core
Notification: BeginRequest
Handler: Not yet determined
Error Code: 0x80070021
Config Error: This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
And the Config Source looks like this:
144: </modules>
145: <handlers>
146: <remove name="WebServiceHandlerFactory-Integrated"/>
The error is coming from the fact that I have a system.webServer section in my web.config file that has a handlers child section. The system.webServer section is the exact config section that was laid down by default when I first created the ASP.NET MVC website in Visual Studio. It has the following XML comment above it:
<!--
The system.webServer section is required for running ASP.NET AJAX under Internet
Information Services 7.0. It is not necessary for previous version of IIS.
-->
I take the handlers child section out, and the 500 error goes away. Of course, that section is required for an ASP.NET MVC application to work properly in IIS7, so simply taking it only produces other errors (404 errors in this case since routing doesn't work).
The support engineers at ASPnix claim that ASP.NET MVC is installed and configured properly in IIS7 on their servers. I'm not saying I don't believe them as this is the first ASP.NET MVC site that I've built and deployed. However, I can't think of anything I could do to make this work since it appears to be a config issue at a level that I don't have access to.
This issue smells like it would be a common issue with folks trying to deploy ASP.NET MVC to a hosting provider. Has anything run into this either with ASPnix or other web hosting companies and hopefully found a solution?
ps
One odd thing. When researching this issue on the web I find many people saying they had to set the overrideModeDefault attribute their applicationHost.config files of IIS7 to from "Deny" to "Allow". However, my local development server has this set to "Deny" and everything works fine. Even so, I don't have access to the applicationHost.config file anyway on the web host's server.
Open IIS Management, Under the main server node, select open Feature Delegation (in Management section)
"Handler Mappings" to "Read/Write" instead of "Read Only"
It looks like your hosting provider unnecessarily locked down IIS.
I was able to recreate the problem on my local IIS 7.5 server.
See this for a global settings reset.
please check if you deployed your application properly : Deploying an ASP.NET Server (IIS 7)
The link to
http://www.winservermart.com/Howto/HTTP_Error_500_19_IIS_7.aspx
doesn't fix the problem. The "reset delegation" creates an exception in web.config for a particular domain only which makes the site work, but doesn't answer how to set it permanently system wide.
So, it's not shame, because we know the solution and set all settings correctly. And advertising here some other hosts pointless we have tons of clients that are running from wh4l and describing how great their overloaded servers.
-Polk

Resources