Using ELMAH inside my asp.net mvc 4 & MVC5 web application - asp.net-mvc

I have two asp.net mvc web applications; asp.net mvc4 and asp.net mvc5 , they are both deployed under iis7 on two separate VMs.
now i am currently facing problems when un-handled exceptions are raised,,, because users will be re-directed to the Error view inside the shared folder under the view section. and i am unable to know exactly the exception details..
so i have read about using the ELMAH tool which will automatically logs all the UN-handled exceptions. but my question is that what are the steps that i need to follow to configure the tool inside myC application ?
second question; will ELMAH works on asp.net vmc4 and asp.net mvc5 in the same way?
Third question. now i have custom error set to <customErrors mode="RemoteOnly" /> inside my live asp.net mvc web application, since i do not want end users to be exposed to the technical details about any exception, so when using elmah should i set the custom error to be no ?
Thanks

1) Just install Elmah from Nuget. That will enable it with the default configuration to save exceptions to an XML file
2) Yes, it should work both in MVC4 and 5
3) No, you can leave it as it is. The Elmah page is available locally only by default. Users will be still redirected to your Error page, and you can use the elmah URL locally to access the actual error information.

Related

MVC customErrors with redirect to subdomain error page

I have project with set of subdomain websites (.NET MVC).
e.g.
admin.example.com
weather.example.com
test.example.com
error.example.com
All this websites have same style and work as one big project, so my idea is to create one place for error pages as subdomain website (error.example.com). I think that in that case I will get one place where I will support my error pages (design, styling and other things).
My question is how to do that using MVC tools and web.config.
P.S.
Also it will be cool to have one place to log exceptions. For now I'm using elmah to log all exception in database.
It is not a usual thing, so I have a workaround.
I used Application_Error of Global.asax to track redirect.

ASP.NET MVC Sub Application

I have a ASP.NET MVC application at a root level (e.g. http://example.com), and have now deployed an additional ASP.NET MVC application as a sub-application (e.g. http://example.com/api). I have set the sub-application as an "Application" in IIS.
However, whenever I try to navigate to the sub-application, I am getting a 403.14 Forbidden error. It's like the sub-application isn't getting picked up as an ASP.NET MVC application. If I try and hit a url which has a controller/action method in the sub-application (e.g. http://example.com/api/home/index"), I get a 404 response.
In terms of setup, the only differences I can see in IIS Manager is a lack of an "ISAPI Filters" icon for the sub-application. I am running .NET 4.5, ASP.NET MVC 4, and IIS 7.5.
Does anyone have any suggestions on how to get this ASP.NET MVC sub-application working?
Turns out I was missing the following config from the <system.webServer> config in my child application:
<modules runAllManagedModulesForAllRequests="true"/>
After I put that in, it started recognising the child application as an ASP.NET MVC site.

ASP.NET MVC web application exception handling

ASP.NET MVC web application exception handling using application blocks.
How can i configure Microsoft Application blocks for exception handling in .NET MVC2 web application logging the error to the sql database?
You can write own Library bur this is not easy so i prefer u Use Elmah
I think elmah is good because now 588,786 is downloaded so we safely to use.
You can simply install
PM> Install-Package elmah
ELMAH with initial configuration for getting started quickly. ELMAH
(Error Logging Modules and Handlers) is an application-wide error
logging facility that is completely pluggable. It can be dynamically
added to a running ASP.NET web application, or even all ASP.NET web
applications on a machine, without any need for re-compilation or
re-deployment.
You might want to think about ELMAH. It is much lighter than Application Blocks and you can use it as a filter for handling errors.

Hosting an MVC and a webforms site on the same IIS7 instance - web.config inheritance

We have a website that was written in classic ASP, then I started to extend it using web forms. These extensions exist in a subfolder of the main folder. Now we've decided we'd prefer to use MVC3. Also, as we'd like to convert all our site to MVC3 over time, we are hosting the MVC code in the application root. I've found some other questions where people have a similar issue to mine, but no solution. The issue is simply that my web forms app can't seem to be stopped from inheriting the web.config settings from the root folder, and as a result, it won't run, it either complains about missing dlls, or complains about running the wrong version of .NET, or complains I need to remove some settings ( which I try and can never get to work right ). The app in the subfolder is also hosting a webservice that is called by our application, and it also runs HTTP handlers to protect our imaging content, so it's got a bit of stuff in it. Do I need to run my MVC site in a subfolder ? Is there any way to have MVC in the folder above a web forms app ? I'd prefer to set things up so they share session data, but that's looking likely to be impossible at this stage...
So to be clear the folder structure is:
<root>
contains asp site and MVC site.
<subfolder>
contains webforms application
</subfolder>
</root>
and my issue is getting the subfolder to run, preferably in the same session as the MVC app.
There is no reason you can't run regular .aspx files on an MVC site. You are correct though, web.config settings are inherited from the parent (chain), but you just add a new web.config in your directory with relevant settings.
What you will have to do is play with the routes, because by default MVC will route all requests into your controller classes. But if you google around its fairly simple to add an exception to the routing.
If you post some of the specific errors we can probably help further.
Oh and do you mean Classic ASP? i.e. not Classic ASP.NET? Because you'll have fun sharing session data between ASP & ASP.NET.

ASP.NET MVC (Form login): Validation of viewstate MAC failed

Im trying to use ASP.NET login controls, in a ASP.NET MVC project and i get this error, when i click the submit button:
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
I have searched google and tried alot of solution, which worked for others including:
- Install .NET 3.5 SP1
-
- Check if there is only 1 on the page
Unfortunaly notthing works. Do you guys have any other suggentions?
/Thanks
Create a new MVC Webapplication and take a look at how FormsAuthentication is done there. You can't use the Login Controls.

Resources