I've asked this on the elmah group in google groups but am still mystified so I thought I'd throw it out to a larger pool. Here's the original note with my code as it currently stands.
I have ELMAH set up on my MVC 5 application and I want to use a custom email service to send email instead of using the smtp send that is set up by default. (This is an organizational preference.) I've been poking around at it but can't figure out how to do this. My service call is working just fine, but I can't hook it up so that it runs when there is an exception. Any assistance will be greatly appreciated.
What I've got set up is the following:
Web.config (removed non-elmah-related lines):
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<configSections>
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
</configSections><appSettings>
...
<add key="elmah.mvc.disableHandler" value="false" />
<add key="elmah.mvc.disableHandleErrorFilter" value="false" />
<add key="elmah.mvc.requiresAuthentication" value="false" />
<add key="elmah.mvc.IgnoreDefaultRoute" value="false" />
<add key="elmah.mvc.allowedRoles" value="*" />
<add key="elmah.mvc.allowedUsers" value="*" />
<add key="elmah.mvc.route" value="elmah" />
</appSettings>
<connectionStrings>
<add name="BFRDPDB" providerName="System.Data.SqlClient" connectionString="blahblah;" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5.1" />
<customErrors mode="Off" defaultRedirect="~/Home/Error">
<error statusCode="404" redirect="~/Home/Error" />
</customErrors>
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="BFRDP.Infrastructure.ErrorMailModule" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
<add name="ErrorMail" type="BFRDP.Infrastructure.ErrorMailModule" preCondition="managedHandler" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
</modules>
</system.webServer>
<elmah>
<security allowRemoteAccess="false" />
<errorLog type="Elmah.SqlErrorLog, Elmah"
connectionStringName="BFRDPDB"
applicationName="FarmAnswers.org" />
</elmah>
<location path="elmah">
<system.web>
<httpHandlers>
<add verb="POST,GET,HEAD"
path="elmah.axd"
type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
<authorization>
<allow roles="SuperAdmin" />
<deny users="*" />
</authorization>
</system.web>
<system.webServer>
<handlers>
<add name="ELMAH"
verb="POST,GET,HEAD"
path="elmah"
type="Elmah.ErrorLogPageFactory, Elmah"
preCondition="integratedMode" />
</handlers>
</system.webServer>
</location>
</configuration>
And my ErrorMailModule.cs file looks like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
namespace BFRDP.Infrastructure
{/// <summary>
/// Summary description for ErrorMailModule
/// </summary>
public class ErrorMailModule : Elmah.ErrorMailModule
{
public ErrorMailModule()
{
}
protected override void SendMail(MailMessage mail)
{
if (mail == null)
throw new ArgumentNullException("mail");
// Code to send email here through internal provider
}
}
}
My error is indeed logged in the database, but the code to send the email is never reached.
What am I doing wrong?
Added the errorMail settings in the section of my web.config and the app was able to get to my custom module:
<elmah>
<security allowRemoteAccess="false" />
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="BFRDPDB" applicationName="FarmAnswers.org" />
<errorMail
from="elmah#example.com"
to="admin#example.com"
subject="..."
priority="Low"
async="true"
smtpPort="25"
smtpServer="smtp.example.com"
useSsl="true"
userName="johndoe"
password="secret"
noYsod="true" />
</elmah>
Related
I having trouble with pro asp.net mvc 5 book by Adam Freeman. When I try to start debugging, I catch the error:
An exception of type 'System.ArgumentException' occurred in System.Data.dll but was not handled in user code Additional information: Keyword not supported: 'initialcatalog'.But my Web.config not such as in the book.
Screen:[1]: http://imgur.com/3TpOL0E
My Web.config code:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="EFDbContext" connectionString="Data Source=(localdb)\v11.0; InitialCatalog=SportsStore; Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
P.S. Sorry my google translate English.
Try adding a space in the connection string like so:
Initial Catalog=SportsStore;
I just deployed a new MVC4 app to my server and some of the CSS, JS, and images are not loading. For example, the Chrome console says,
Failed to load resource: the server responded with a status of 500
(Internal Server Error)
http://beta.vinformative.com/Content/themes/base/jquery-ui-1.8.20.custom.css
Failed to load resource: the server responded with a status of 500
(Internal Server Error)
http://beta.vinformative.com/Content/select2.css
Failed to load resource: the server responded with a status of 500 (Internal Server
Error) http://beta.vinformative.com/Scripts/Plugins/select2.js
Failed to load resource: the server responded with a status of 500 (Internal
Server Error) http://beta.vinformative.com/Scripts/WineCreate.js
Failed to load resource: the server responded with a status of 500
(Internal Server Error)
http://beta.vinformative.com/Content/images/logo_revisedsmall.png
They are all available on server in the locations they mention. I've been troubleshooting other things all night, so I'm a little blurry eyed and maybe I'm missing something obvious. You can see these errors right on the homepage at beta.vinformative.com as well.
Here is a screenshot of my file layout too from the server:
I am using bundling and published the site to file system in release mode, but I wouldn't expect that to effect the images, would it? I'm going to keep at this, but any help would be greatly appreciated! Thanks!
EDIT as requested bundle config: THANKS!
public class BundleConfig
{
// For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/Libraries/jquery-{version}.js",
"~/Scripts/Plugins/jquery.loaderbutton.js",
"~/Scripts/Plugins/jquery.form.js"));
bundles.Add(new ScriptBundle("~/bundles/base").Include(
"~/Scripts/Feedback.js",
"~/Scripts/Global.js",
"~/Scripts/WineSearch.js"
));
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
"~/Scripts/Libraries/jquery-ui-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/Libraries/jquery.validate*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap/bootstrap.js",
"~/Scripts/bootstrap/bootbox.js",
"~/Scripts/bootstrap/bootstrap-notify.js"
));
bundles.Add(new ScriptBundle("~/bundles/formhelpers").Include(
"~/Scripts/bootstrap/Form Helpers/bootstrap-formhelpers-countries.js",
"~/Scripts/bootstrap/Form Helpers/bootstrap-formhelpers-countries.en_US.js",
"~/Scripts/bootstrap/Form Helpers/bootstrap-formhelpers-phone.js",
"~/Scripts/bootstrap/Form Helpers/bootstrap-formhelpers-phone.format.js",
"~/Scripts/bootstrap/Form Helpers/bootstrap-formhelpers-states.js",
"~/Scripts/bootstrap/Form Helpers/bootstrap-formhelpers-states.en_US.js"
));
bundles.Add(new ScriptBundle("~/bundles/winedetails").Include(
"~/Scripts/WineDetails.js",
"~/Scripts/Plugins/jquery.uploadifive.js",
"~/Scripts/Plugins/jquery.fileDownload.js",
"~/Scripts/Plugins/jquery.fancybox.js",
"~/Scripts/Plugins/jquery.fancybox-media.js",
"~/Scripts/Plugins/jquery.nailthumb.1.1.js",
"~/Scripts/Plugins/jquery.lazyload.js"
));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css", "~/Content/slideout.css"));
bundles.Add(new StyleBundle("~/Content/themes/bootstrap/css").Include(
"~/Content/themes/bootstrap/bootstrap.css",
"~/Content/themes/bootstrap/bootstrap-responsive.css",
"~/Content/themes/bootstrap/bootstrapSwitch.css",
"~/Content/themes/bootstrap/bootstrap-notify.css",
"~/Content/themes/bootstrap/bootstrap-formhelpers.css"
));
bundles.Add(new StyleBundle("~/Content/datatables").Include(
"~/Content/jquery.dataTables.css",
"~/Content/jquery.dataTables_themeroller.css"));
bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/chosen.css"));
bundles.Add(new StyleBundle("~/Content/sitewide").Include(
"~/Content/themes/base/jquery.ui.autocomplete.css",
"~/Content/Site.css"
));
bundles.Add(new StyleBundle("~/Content/winedetails").Include(
"~/Content/uploadifive.css",
"~/Content/themes/fancybox/jquery.fancybox.css"
));
bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
"~/Content/themes/base/jquery.ui.core.css",
"~/Content/themes/base/jquery.ui.resizable.css",
"~/Content/themes/base/jquery.ui.selectable.css",
"~/Content/themes/base/jquery.ui.accordion.css",
"~/Content/themes/base/jquery.ui.autocomplete.css",
"~/Content/themes/base/jquery.ui.button.css",
"~/Content/themes/base/jquery.ui.dialog.css",
"~/Content/themes/base/jquery.ui.slider.css",
"~/Content/themes/base/jquery.ui.tabs.css",
"~/Content/themes/base/jquery.ui.datepicker.css",
"~/Content/themes/base/jquery.ui.progressbar.css",
"~/Content/themes/base/jquery.ui.theme.css"));
}
}
EDIT # 2
I tried to change my reference in my _layout view with no luck:
from
<link href="../../Content/themes/base/jquery-ui-1.8.20.custom.css" rel="stylesheet"
to
<link href="#Url.Content("~/Content/themes/base/jquery-ui-1.8.20.custom.css")" rel="stylesheet">
EDIT #3 Web.config
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<sectionGroup name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection, DotNetOpenAuth.Core">
<section name="messaging" type="DotNetOpenAuth.Configuration.MessagingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" />
<section name="reporting" type="DotNetOpenAuth.Configuration.ReportingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" />
<section name="openid" type="DotNetOpenAuth.Configuration.OpenIdElement, DotNetOpenAuth.OpenId" requirePermission="false" allowLocation="true" />
<section name="oauth" type="DotNetOpenAuth.Configuration.OAuthElement, DotNetOpenAuth.OAuth" requirePermission="false" allowLocation="true" />
</sectionGroup>
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
<section name="web.optimization" type="Web.Optimization.Configuration.OptimizationSection" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<connectionStrings>
<add name="Elmah" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=elmah;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="vfContext" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=vf3;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<customErrors mode="On" defaultRedirect="~/Error/Generic">
<error statusCode="404" redirect="~/Error/NotFound" />
<error statusCode="500" redirect="~/Error/internal" />
</customErrors>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
<remove name="BundleModule" />
<add name="BundleModule" type="System.Web.Optimization.BundleModule" />
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<staticContent>
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
<mimeMap fileExtension=".m4v" mimeType="video/m4v" />
<mimeMap fileExtension=".ogg" mimeType="video/ogg" />
<mimeMap fileExtension=".ogv" mimeType="video/ogg" />
<mimeMap fileExtension=".webm" mimeType="video/webm" />
<mimeMap fileExtension=".oga" mimeType="audio/ogg" />
<mimeMap fileExtension=".spx" mimeType="audio/ogg" />
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
<mimeMap fileExtension=".svgz" mimeType="image/svg+xml" />
<remove fileExtension=".eot" />
<mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
<mimeMap fileExtension=".otf" mimeType="font/otf" />
<mimeMap fileExtension=".woff" mimeType="font/x-woff" />
<remove fileExtension=".manifest" />
<mimeMap fileExtension=".manifest" mimeType="text/cache-manifest" />
</staticContent>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="RazorEngine" publicKeyToken="9ee697374c7e744a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.8.0" newVersion="3.0.8.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
</dependentAssembly>
</assemblyBinding>
<legacyHMACWarning enabled="0" />
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
<system.net>
<defaultProxy enabled="true" />
<mailSettings>
<smtp from="mailer#vinformative.com">
<network host="smtp.emailsrvr.com" port="2525" userName="mailer#vinformative.com" password="vinf0rmat1ve" />
</smtp>
</mailSettings>
<settings>
<!-- This setting causes .NET to check certificate revocation lists (CRL)
before trusting HTTPS certificates. But this setting tends to not
be allowed in shared hosting environments. -->
<!--<servicePointManager checkCertificateRevocationList="true"/>-->
</settings>
</system.net>
<dotNetOpenAuth>
<messaging>
<untrustedWebRequest>
<whitelistHosts>
<!-- Uncomment to enable communication with localhost (should generally not activate in production!) -->
<!--<add name="localhost" />-->
</whitelistHosts>
</untrustedWebRequest>
</messaging>
<!-- Allow DotNetOpenAuth to publish usage statistics to library authors to improve the library. -->
<reporting enabled="true" />
<openid>
<relyingParty>
<security requireSsl="false">
<!-- Uncomment the trustedProviders tag if your relying party should only accept positive assertions from a closed set of OpenID Providers. -->
<!--<trustedProviders rejectAssertionsFromUntrustedProviders="true">
<add endpoint="https://www.google.com/accounts/o8/ud" />
</trustedProviders>-->
</security>
<behaviors>
<!-- The following OPTIONAL behavior allows RPs to use SREG only, but be compatible
with OPs that use Attribute Exchange (in various formats). -->
<add type="DotNetOpenAuth.OpenId.RelyingParty.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth.OpenId.RelyingParty" />
</behaviors>
</relyingParty>
</openid>
</dotNetOpenAuth>
<uri>
<!-- The uri section is necessary to turn on .NET 3.5 support for IDN (international domain names),
which is necessary for OpenID urls with unicode characters in the domain/host name.
It is also required to put the Uri class into RFC 3986 escaping mode, which OpenID and OAuth require. -->
<idn enabled="All" />
<iriParsing enabled="true" />
</uri>
<elmah>
<!--
See http://code.google.com/p/elmah/wiki/SecuringErrorLogPages for
more information on remote access and securing ELMAH.
-->
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="Elmah"></errorLog>
<errorMail from="mailer#vinformative.com" to="support#vinformative.com" subject="ELMAH Error Log Mail"></errorMail>
<security allowRemoteAccess="false" />
</elmah>
<location path="elmah.axd" inheritInChildApplications="false">
<system.web>
<httpHandlers>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
<!--
See http://code.google.com/p/elmah/wiki/SecuringErrorLogPages for
more information on using ASP.NET authorization securing ELMAH.
<authorization>
<allow roles="admin" />
<deny users="*" />
</authorization>
-->
</system.web>
<system.webServer>
<handlers>
<add name="ELMAH" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
</handlers>
</system.webServer>
</location>
<web.optimization>
<bundles>
<bundle virtualPath="~/Content/sample" transform="System.Web.Optimization.JsMinify, System.Web.Optimization">
<content>
<!-- Add some single files -->
<!-- <add path="~/Scripts/validation.js" /> -->
<!-- <add path="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js" /> -->
<!-- Add a directory (and its subdirectories) -->
<!-- <add path="~/Scripts/Plugins" searchPattern="*.js" searchSubdirectories="true" /> -->
</content>
<!--
If you want to apply multiple transformations,
you should remove the "transform" attribute from the bundle.
-->
<!--
<transformations>
<add type="Web.Optimization.Bundles.CoffeeScript.CoffeeScriptTransform, Web.Optimization.Bundles.CoffeeScript" />
<add type="System.Web.Optimization.JsMinify, System.Web.Optimization" />
</transformations>
-->
</bundle>
</bundles>
</web.optimization>
</configuration>
Only non-bundled CSS and JS and img tags are not rendering.
FIXED!
I commented out the following in my node:
<staticContent>
<!-- <mimeMap fileExtension=".mp4" mimeType="video/mp4" />
<mimeMap fileExtension=".m4v" mimeType="video/m4v" />
<mimeMap fileExtension=".ogg" mimeType="video/ogg" />
<mimeMap fileExtension=".ogv" mimeType="video/ogg" />
<mimeMap fileExtension=".webm" mimeType="video/webm" />
<mimeMap fileExtension=".oga" mimeType="audio/ogg" />
<mimeMap fileExtension=".spx" mimeType="audio/ogg" />
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
<mimeMap fileExtension=".svgz" mimeType="image/svg+xml" />
<remove fileExtension=".eot" />
<mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
<mimeMap fileExtension=".otf" mimeType="font/otf" />
<mimeMap fileExtension=".woff" mimeType="font/x-woff" />-->
<remove fileExtension=".manifest" />
<mimeMap fileExtension=".manifest" mimeType="text/cache-manifest" />
</staticContent>
Comment out this under system.webserver in web.config
<staticContent>
<!-- <mimeMap fileExtension=".mp4" mimeType="video/mp4" />
<mimeMap fileExtension=".m4v" mimeType="video/m4v" />
<mimeMap fileExtension=".ogg" mimeType="video/ogg" />
<mimeMap fileExtension=".ogv" mimeType="video/ogg" />
<mimeMap fileExtension=".webm" mimeType="video/webm" />
<mimeMap fileExtension=".oga" mimeType="audio/ogg" />
<mimeMap fileExtension=".spx" mimeType="audio/ogg" />
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
<mimeMap fileExtension=".svgz" mimeType="image/svg+xml" />
<remove fileExtension=".eot" />
<mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
<mimeMap fileExtension=".otf" mimeType="font/otf" />
<mimeMap fileExtension=".woff" mimeType="font/x-woff" />-->
<remove fileExtension=".manifest" />
<mimeMap fileExtension=".manifest" mimeType="text/cache-manifest" />
</staticContent>
I added app.UseStaticFiles(); this code in starup.cs of Configure method, than it is fixed.
My fix ended up being to rename my solution file and delete a directory found under the ".vs" folder. Issue precursors - Using VS2019, I created an ASP.NET Core app that had the same name as my solution file. I had meant to create a full-framework asp.net project and so I removed/deleted the ASP.NET Core project from the solution and created a new full-framework with the same name. I believe this caused IIS Express to continue using some of the remnant configuration found under the ".vs\" folder that was telling it to use some ASP.NET Core modules.
This worked for me:
Close Visual Studio
Change my solution name to something different from my web project name
Remove the directory described above that was under the .vs folder
Reopen Visual Studio and run the web project
I have an MVC 3 application that is giving me a 401 error when I try and access it from the remote server, but when I run it from my local computer it runs with out any error.
The remote server has IIS 7 configured to allow both Forms and Anonymous access and successfully serves static files (content files), it's only when I try and access the MVC application that I'm getting issues.
When I browse to the MVC application, I get a prompt that says, "Windows Security - The server at requires a username and password. Warning: This server is requesting that your username and password be sent in an insecure manner (basic authentication without a secure connection)."
I've tried entering all the passwords I can think of, and nothing give me access.
When I click cancel, I get a server error that says, "401 - Unauthorized: Access is denied due to invalid credentials. You do not have permission to view this directory or page using the credentials that you supplied." and I've been redirected to the LogOn page
My Web.config file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=152368
-->
<configuration>
<configSections>
<section name="razorJSSettings" type="RazorJS.Configuration.RazorJSSettings, RazorJS" />
</configSections>
<connectionStrings>
<!--<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />-->
<add name="ApplicationServices" connectionString="Data Source=SOURCE; Initial Catalog=thedb; User ID=thedbuser; Password='thedbuserpassword';" />
<add name="GestmeDataContext" connectionString="metadata=res://*/Models.Gestme.csdl|res://*/Models.Gestme.ssdl|res://*/Models.Gestme.msl;provider=System.Data.SqlClient;provider connection string="data source=SOURCE;initial catalog=thedb;persist security info=True;user id=thedbuser;password=thedbuserpassword;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="1.0.0.0" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<customErrors mode="Off" />
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
</profile>
<roleManager enabled="true">
<providers>
<clear />
<add connectionStringName="ApplicationServices" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
</providers>
</roleManager>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
<httpHandlers>
<add path="razorjs.axd" verb="GET" type="RazorJS.RazorJSHandler" />
</httpHandlers>
</system.web>
<system.webServer>
<httpErrors errorMode="Detailed" />
<asp scriptErrorSentToBrowser="true"/>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<add name="RazorJSHandler" path="razorjs.axd" verb="GET" type="RazorJS.RazorJSHandler" />
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.8.0" newVersion="4.0.8.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<razorJSSettings handlerPath="~/razorjs.axd">
<!-- If empty all paths are valid -->
<allowedPaths>
<add path="~/Scripts" />
</allowedPaths>
</razorJSSettings>
</configuration>
What are all the issues that could cause 401 errors to be returned from the server? Could it be the connection from the database to the server or the aspnet_* tables?
So, the actual reason was kinda dumb. I had a partial view on the masterpage that had the [Authorize] attribute associated with its action result.
Just in case anyone else gets that same error!
I believe this is because you are using the AspNetWindowsTokenRoleProvider. This is trying to get the role for the user on the local server, not from Windows Forms.
You should be specifying the SqlRoleProvider.
please go to the "Authentication Method" in Default Web Site in IIS and checked on "Integrated Windows Authenticaton". This might be work.
I cannot figure this out. Elmah isn't logging exceptions that happen inside a Controller. For example, no email is generated for this:
[Authorize]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Reply(ReplyViewModel viewModel)
{
throw new Exception("Test");
....
}
Web.config looks like this:
configuration>
<configSections>
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
</configSections>
<elmah>
<!--<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="elmah-sql" >
</errorLog>-->
<errorMail from="somewhere#somewhere.com"
to="errors#somewhere.com"
subject="Error Subject Line"
async="true"
smtpPort="25"
smtpServer="ourstmpserver">
</errorMail>
</elmah>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear />
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
<httpModules>
<!--<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />-->
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>
<httpHandlers>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<!--<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />-->
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
</modules>
<handlers>
<add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
But, if I navigate to a URL for which I have no Controller/Action, I will get an email from Elmah.
What gives? I really need emails when Exceptions happen...
Try using Elmah.Contrib.Mvc available on NuGet.
We use this package, and register their HandleErrorAttribute in our Global.asax, like so:
private static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
//filters.Add(new HandleErrorAttribute()); // default MVC setting
filters.Add(new ElmahHandleErrorAttribute()); // from Elmah.Contrib.Mvc
}
I had the exact same problem, and eventually solved it by using the source for debugging: Download Source
In my case, Thread.CurrentPrincipal was replaced by a CurrentPrincipal with Identity = null, which caused an Exception, since Elmah is using CurrentPrincipal.Identity.Name.
All exceptions inside Elmah itself are catched to prevent your program from crashing as a result of a logging exception, in which case the original Exception is also lost.
This is just an example of what went wrong in my case, any exception caused in Elmah itself will result in this behavior. Therefore the source should be used to debug. An alternative could be to look at the Trace, since Elmah is writing any catched exceptions to the Trace.
I am playing around with Elmah to see if I want to use that as my error handling solution. I installed it, hard coded an exception into my page, hit the page wholla! Got my email, everything is happy. However, when I added the customError node to my web.config to redirect to a friendly error page, the email was not sent but I was redirected to my friendly error page.
Strangely, when I browsed to a page that doesn't exist on my site, I was redirected to home (as I set in my customErrors) but I DID receive the email...that could be problematic as I don't want to get a billion emails when people hit my site and add "whatever.php" to the end of the url.
So I have two questions: 1) why would the exception that is being thrown NOT send me an email and 2) how can I tell Elmah NOT to send me emails for 404s?
You can filter things with elmah like such in your Global.asax.cs:
//ELMAH Filtering
protected void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
{
FilterError404(e);
}
protected void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs e)
{
FilterError404(e);
}
//Dimiss 404 errors for ELMAH
private void FilterError404(ExceptionFilterEventArgs e)
{
if (e.Exception.GetBaseException() is HttpException)
{
HttpException ex = (HttpException)e.Exception.GetBaseException();
if (ex.GetHttpCode() == 404)
{
e.Dismiss();
}
}
}
So add the call to FilterError404 to any part of the filtering. The above example will have it filter 404 for both ErrorLog and Email. Also check out:
http://code.google.com/p/elmah/wiki/ErrorFiltering
You can also do Filtering By Source as described in the link:
<elmah>
...
<errorFilter>
<test>
<and>
<equal binding="HttpStatusCode" value="404" type="Int32" />
<regex binding="FilterSourceType.Name" pattern="mail" />
</and>
</test>
</errorFilter>
</elmah>
Check web.config:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<configSections>
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
</configSections>
<appSettings />
<!-- ELMAH: Configuration -->
<elmah>
<security allowRemoteAccess="1" />
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="Elmah.Sql" />
<errorMail defaultCredentials="true" from="someuser#example.com" to="someuser#example.com, someuser2#example.com" subject="Error (STAGING): {0}" async="true" smtpPort="25" smtpServer="192.168.1.1" userName="smtpUserName" password="smtpPassword" />
</elmah>
<connectionStrings>
<add name="Elmah.Sql" connectionString="Data Source=192.168.1.1;database=DBName;integrated security=false;User ID=MyUserName;Password=MyPassword" />
</connectionStrings>
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="someuser#example.com">
<network defaultCredentials="true" host="192.168.1.1" port="25" userName="smtpUserName" password="smtpPassword" />
</smtp>
<!-- Use this setting for development
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="C:\Temp" />
</smtp>
-->
</mailSettings>
</system.net>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true">
<assemblies>
...........................
</assemblies>
</compilation>
.......................
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
-->
<customErrors mode="RemoteOnly" defaultRedirect="~/Home/MyErrorPage" />
.............................
<httpHandlers>
..............................
<!--ELMAH-->
<add verb="POST,GET,HEAD" path="/MyErrorPage/elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
<httpModules>
........................
<!-- ELMAH: Logging module -->
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
</httpModules>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
.............................
<!-- ELMAH-->
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</modules>
<handlers>
..............
<!--ELMAH-->
<add name="Elmah" verb="POST,GET,HEAD" path="/MyErrorPage/elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</handlers>
</system.webServer>
..................
</configuration>
FYI: NuGET Package also available as explained by Scott Hanselman:
http://www.hanselman.com/blog/NuGetPackageOfTheWeek7ELMAHErrorLoggingModulesAndHandlersWithSQLServerCompact.aspx