mvc3 error on webserver, only get generic response - asp.net-mvc-3

Edit: showed my exact web.config code.
I have a MVC3 project that works fine on my box, but when I upload it to the web server, it gives an error on a certain page. I am trying to determine the exact error, but it keeps redirecting to the "Error/ShowError" action. I tried modifying the web.config file to say showcustomerrors=false, but it still redirects. I really need to see the actual error in order to troubleshoot the problem.
In firebug, it shows that the error is a 500 internal server error. I haven't been able to get any more detailed than that.
Also, if I run the page from my local box, but use the remote database, I don't get an error. This makes me think it's related to directory permissions.
Here is in my web.config section:
<compilation debug="true" targetFramework="4.0">
Here is in my web.debug.config section:
<customErrors mode="Off">
Thanks!

See if these changes will help.
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" />
</system.webServer>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true"/>
</system.web>
</configuration>
If not, make sure that AspNet is properly installed.
C:\Windows\Microsoft.Net\Framework..\v.....\aspnet_regiis.exe -i
Edit:
You can try to log the exception message using the following method in Global.asax.cs
protected void Application_Error(object sender, EventArgs e) {
var exception = Server.GetLastError();
// Log the exception
}
Edit:
Well, this will be a lot to do, but I suggest you to add Elmah to your project to log unhandled exceptions. See the first step on Logging in MVC Part 1- Elmah
Elmah is available on NuGet Gallery.

Turn off customErrors in web.config and you will be able to see what the error is. then fix it. Turn the Custom Error on
<customErrors defaultRedirect="Error.aspx" mode="Off"/>

Here are the options you have for custom errors:
<customErrors defaultRedirect="url"
mode="On|Off|RemoteOnly">
<error. . ./>
</customErrors>
I think your issue is that you're using 'false' instead of 'Off'.
Good luck, hope this works for you.
Reference: MSDN link for CustomErrors section

Related

Strange Configuration Error in web.config

I am getting the following error in my WebApi application:
An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. Parser Error Message: Unrecognized attribute 'MaxCachedResults'. Note that attribute names are case-sensitive.
This is my roleManager entry in web.config and as you can see I am not specifying the MaxCachedResults attribute, although I did add this initially, I removed it so it's no longer being used and I'm not sure where it's picking this up from.
<roleManager enabled="true" defaultProvider="MyRoleProvider" cacheRolesInCookie="false">
<providers>
<clear />
<add name="MyRoleProvider" type="SiteWorksAPI.RoleProviders.MyRoleProvider, SiteWorksAPI" connectionStringName="SiteWorks" applicationName="/" />
</providers>
</roleManager>
The error happens when I call var resp = await _httpClient.GetAsync(resourceUri) and inspecting resp.Content.ReadAsStringAsync().Result displays a 'Configuration Error' HTML page with the above error message.
I have tried all of the following with any success:
Rebooted my PC
Recycled the application pools
Restarted IIS
Cleared down the Tempoary ASP.NET directory
Does anyone know what's going on here?
It seems that Castle Windsor was caching an older copy of the web.config file. After changing the caching options on the WebRequestHandler I was able to get the HttpClient to pick up the new web.config file.

Unable to redirect to error page in MVC

I tried to redirect to error page on error. but it does not work.
It just giving - Uh-oh, something went wrong! Error Code: 500 message on browser instead of redirecting to error page. error page is already existed in shared folder.
Below is the code in controller:
[HandleError(View = "Error")]
public ActionResult Index()
{
int u = Convert.ToInt32("");// Error line
return View();
}
web config has included below line:
<customErrors mode="On" defaultRedirect="Error"></customErrors>
did google but, it shows above stuff and it should work but still not work.
Using MVC 4 basic template.
Please guide.
thanks
Errors can occur in the error view itself. In that case, the default ASP.NET error page is displayed. To avoid this, you can configure the application to display an error file in the customErrors section of the Web.config file, as shown in the following example:
<system.web>
<customErrors mode="On" defaultRedirect="GenericErrorPage.htm">
<error statusCode="500" redirect="/Error.htm" />
</customErrors>
</system.web>

httpErrors not redirecting to correct page with MVC 3

I am trying to set up http custom error pages in my MVC 3 web application. I have added the following to my web.config:
<httpErrors errorMode="Custom" defaultResponseMode="ExecuteUrl" defaultPath="/Error/404">
<clear />
<error statusCode="500" path="/Error/404"
</httpErrors>
When a 500 error occurs on a request I expected this to redirect the user my.domainname.com/Error/404.
I have an Error controller which contains one action called error, I have mapped requests for 404 to this action.
When I force a 500 error (verified by chrome developer tools network tab) on the website I receive a blank page with the following message:
"The page cannot be displayed because an internal server error has occurred."
If I remove the httpErrors section from my web.config then I get the actual exception message. Therefore the httpErrors section I have in the web.config must be working, I just do not understand how to set it up correctly.
Here is a list of the attributes I have picked and why:
errorMode="Custom": So that I can see the custom error page and verify it is working before changing it to local only.
defaultResponseMode="ExecuteUrl": This should allow me to specify a server relative url as the path, which sounds like what I want as I want to hit a controller action.
defaultPath="/Error/404": The relative url I want requested if I do not specify one.
Edit:
I should add that the site is running on IIS 7.5. I also do not wish to use the tag as this is designed to work with IIS 6 and should be used for IIS 7+.
Try using the customErrors section in the web.config (inside system.web) instead.
http://msdn.microsoft.com/en-us/library/h0hfz6fc.aspx
e.g.
<customErrors mode="On">
<error statusCode="404" redirect="Error/404" />
<error statusCode="500" redirect="Error/500" />
</customErrors>
It should be like Controller/Action/Id. In your case Action is missing. Check following example and change it as per your action methods...
<system.web>
<customErrors mode="On" defaultRedirect="/Error/Index/" >
<error statusCode="401" redirect="/Error/NoAccess/" />
<error statusCode="404" redirect="/Error/NotFound/" />
</customErrors>
....
</system.web>

Disable OutputCaching in MVC3 when running in DEBUG or under Debugger?

I am trying to disable output caching in a MVC3 app when in debug. I am specifying output caching in the controllers (via the attribute) but don't want to have to #if DEBUG all over my code. I expected this to work:
// In Web.config.debug
<system.web>
<caching>
<outputCache enableOutputCache="false"
xdt:Transform="Replace" />
</caching>
But this seems to be ignored. Any other ideas how to do it system wide without nasty global.asax code or #if DEBUGs everwhere?
The web.config.debug file is used only when you build a deployment package. If you run your site locally in Cassini for example it is completely ignored. So you may try disabling cache in your web.config:
<system.web>
<caching>
<outputCache enableOutputCache="false" />
</caching>
</system.web>
and in your web.config.release enable the cache. Note though that if you don't use the web deployment package feature those files are completely ignored.
I would think that would work as well. You may want to also try setting enableFragmentCache to false. Per this link:
the EnableFragmentCache property is
set to false, no page is cached on the
server, regardless of the settings in
# OutputCache directive or caching
profile used by the page. For more
information, see
OutputCacheSettingsSection and
OutputCacheProfile.
If you use IIS version > 7
You should:
<system.webServer>
<caching enabled="true"/> //false in webconfig.debug
</system.webServer>

"potentially dangerous Request.Form value ..." -- mvc 2, .net 4.0

I am trying to set up input validation using regular expressions, but I keep getting this error when I enter "<test>" in a textbox:
A potentially dangerous Request.Form value was detected from the client
I have this in the web.config:
<system.web>
<httpRuntime requestValidationMode="2.0" />
I also have this in the web.config:
<system.web>
<pages controlRenderingCompatibilityVersion="3.5"
clientIDMode="AutoID"
validateRequest="false">
...
</pages>
and I have this in the page directive of the view in question:
ValidateRequest="false"
Nothing seems to help. I have seen this question on this site and usually the posters leave out the httpRuntime tag in the web.config ... but I have included that and I still get the exception. Any ideas?
OK, I found the answer: [ValidateInput(false)] before the controller or action code! (I didn't go far enough in reading previous questions!)

Resources