Lots of great information on Elmah and MVC 3/4 out there. I've been using Elmah in projects for a few years now.
One thing I haven't seen asked or addressed is displaying Elmah using an MVC site's layout.
Anyone ever try this?
I am developing a MVC-4 project and have Elmah currently running in it's own area. I used the setup at Joel.net
It's working very nice as is, but would really like to hear from the community in regards to displaying the results in a site's layout.
Any tips/suggestions are greatly appreciated.
No, at least not directly. Elmah uses an HttpHandler to display errors, which completely ignores the MVC pipeline.
You have a few options that require some extra work:
Create your own views. You may need to reference the Elmah source as some of the required classes might be internal.
Display Elmah in an iframe in your own view. It's probably not the best option, but it should work.
Try Elmah.MVC, which looks like an MVC controller for Elmah:
Painless integration of ELMAH functionality into ASP.NET MVC
Application. Creates Admin area and corresponding controller, so ELMAH
is availble by /admin/elmah route.
There is a great article over at: http://dotnetdarren.wordpress.com/
It's a pretty comprehensive article on combining Elmah, Health Monitoring, Log4Net, and NLog to cover all the logging you would ever possibly need in any MVC application. It covers the objects as well as the Entity objects, controllers, views, etc., and doing so into one UI for all of them.
The article is dated (2010) and in MVC 2. I was able to take Darren's approach, convert it to VB.NET and get it all running in a large MVC 4 application I am working on.
Even if you don't use it, it's a great tutorial and well worth the read.
Enjoy and mad props to Darren for that article.
If you use the SQL Server module for Elmah, you can save the errors to a SQL database. Once that is done, you could write a custom app or page to read from the DB and present in any manner which you would like.
If ("site's layout" == in-line, on the page){
edit the masterstylesheet to include elmah.
or
wire it into a jQuery plugin.
} else {
have you considered Glimpse's role in the display chain?
}
Related
first let me say, I have started my first ASP.NET MVC (4) application. Before that, I was a forms developer. I love the MVC concept, even though I have not yet fully understood.
In ASP forms times, we could create a control to encapsulate and use it again. I could not figure out yet which element is similar in MVC. I created a Viewed User Control but that hasnt a code-behind file..
Can you give me an example?
Best regards
Patrik
I'm not positive, but perhaps you might be interested in Partial Views. Here is an article on resuable UI Components
Instead of user controls, try razor helpers refer this link for details. http://weblogs.asp.net/scottgu/archive/2011/05/12/asp-net-mvc-3-and-the-helper-syntax-within-razor.aspx
Even though MVC3 is discussed in the blog post, no need to worry. It is not changed in MVC4
Django has the Flatpages app, which lets site admins change content on specific pages without changing code. Flatpage content i stored in the database, sort of like in a CMS. Flatpages are typically used for about-pages and such.
Are there any good equivalents for ASP.Net MVC? I.e., a convenient way to manage page-content persisted to a database.
No.
Django seems closer to a CMS then "ASP.NET MVC" which is both a framework and just a general design pattern.
Have a look at http://http://cmsmvc.codeplex.com, it allows you to create pages, and manage content on the page.
The solution is still in early stages, but it could help you out.
I have an application that will support multiple sites. The site will be determined based on the url.
For example
http://myapp/site/abc123/...
and
http://myapp/site/xyz123/...
The site code will drive a lot of the functionality for example themes, available modules, etc...
Questions:
1-)I need to validate the site code is valid and if it isn't, it should direct the user to an info page. I was looking at using IRouteConstraint, is this appropriate? Are there other/better options?
2-)Any gotchas with this approach (using url to identify site)? Is there are better approach?
Solution
I ended up creating a Custom ActionFilter and check the sitecode in the OnActionExecuting event. That seems to work well and fit better than the IRouteConstraint.
The system I have implemented uses Urls to identify unique page content within a single site and the routing process is pretty straightforward. That being said, you may want to consider making use of Areas in your MVC application. With Areas you can have multiple sections to your website that all have their own MVC structure which can run semi-independently.
Essentially, you will have one base routing definition that lays out some defaults and then the rest of the "sites" will define their own routes pointing to controllers and views in a separate location. It's pretty easy to set up, you'll just need to make sure you're using version 2.0 of ASP.NET MVC. Here's a decent looking tutorial on ASP.NET MVC Areas and Routes. In the current model which MVC 2.0 supports you'll have a single Web project for each area, but that is not necessarily a requirement. Phil Haacked has some code for ASP.NET MVC Single Project Areas if you're looking for another example of the technique, although you, personally, will probably benefit more from the first article.
So long as you define good routes that have clear and measurable constraints, you shouldn't have too much trouble laying out the website you've described.
I ended up creating a Custom ActionFilter and check the sitecode in the OnActionExecuting event. That seems to work well and fit better than the IRouteConstraint.
I'm curious to know if any basic CMS code has been written for ASP.NET MVC.
The reason I ask is, I'm making a data-driven website for a client, and I've already spent a significant amount of time building it from the ground-up in MVC, but now the client wants content management facilities.
Basically they want to be able to add/edit/remove articles and have revision control.
It would be great if I could somehow 'bolt on' the content management without having to start again from scratch, developing it under an existing CMS.
Should I build the article management and revision control myself, or should I re-use some existing package?
N2 does what you describe - "bolts on" to existing ASP.NET solutions (including MVC).
Also, kooboo is interesting http://www.kooboo.com
(I know this question is old, but it still comes high up for the relevant search terms.)
Today I discovered Meek, http://www.adventuretechgroup.com/labs-meek/, and it was very simple and unobtrusive to add to my MVC project, which I believe is what the original poster would have wanted - bolting on CMS as a feature rather than having it take over your entire site.
Piranha CMS is well suited to bolting on to an existing application. The author of it describes why and how here. To quote straight from that source:
"Our focus is content management and to have a transparent and lightweight API for developers. Piranha CMS has almost no components or helpers that render any HTML at all, it simply provides a database, a manager interface and a routing mechanism for retrieving the correct data for the current request.
In the case of you having an existing website you could actually bypass the routing completely, add one page at a time in the manager interface and then manually load the Page model in you existing page. This would allow you to keep your original application exactly the same but manage the content form the manager interface."
If you are still looking, I've published my new open source CMS here:
MVCwCMS
I'm actively working on it so I will push more updates soon.
Here is also a quick summary as to how Telerik Sitefinity does it:
http://www.sitefinity.com/mvc-cms
in brief - allows you to plug in standard system.web.mvc.controller classes as widgets, lets you use the API for anything including model binding, standard Razor for a view engine etc.
There is also Oxite which I believe is more of a blog engine.
Heve a look at AtomicCms it's a free open source content management system based on ASP.NET MVC 1.0
http://atomiccms.codeplex.com
Check for Orchard ;-)
It is based on asp.net mvc.
What would be best practice to localize your ASP.NET MVC application?
I would like to cover two situations:
one application deployment in IIS which would handle multiple languages
one language/application deployment.
In first situation should you go with some kind of view based thing like, ~/View/EN, ~/View/FI, ~/View/SWE or something different?
What about second case, just application based config via Web.config and point these different languages to different URLs?
You can also take a look here ASP.NET MVC 2 Localization complete guide and ASP.NET MVC 2 Model Validation With Localization these entires will help you if you working with ASP.NET MVC 2.
You would localize your ASP.NET MVC application very much in the same way you would a classic ASP.NET Web Form application.
You wouldn't use different pages/views for each language, but each page would support multiple languages using satellite assemblies.
You can look at Matt Hawley's blog entry for more explanation and examples.
Unfortunately, Matt Hawley's original code doesn't work in the release version of ASP.NET MVC. Check out an updated post: http://blog.eworldui.net/post/2008/10/ASPNET-MVC-Localization-via-View-Engines.aspx
In general, the localization process isn't as smooth in the VS 2008 / ASP.NET MVC world as it is with traditional web forms. http://www.guysmithferrier.com/post/2009/05/Localizing-ASPNET-MVC.aspx
Have a look at Rob Connery's MvcStore project. He does a screencast showing one way to solve the globalization problem.
http://wekeroad.com/2008/04/24/mvcstore-part-5
I've never been convinced of handling localization within a form as Elijah suggests - the different lengths and directions can lead to very complex or vary naff looking forms.
I'm only just starting with MVC but taking the decoupling method you would wan to use the same controller regardless of the language (treating language just as a view) - this would then give you /Controller/Action/language/form
There is good tutorial with recent update on How to localize asp.net mvc application covering all aspects including DisplayName localization, Validation, using Routing (storing culture name in URL), issues with output cache and so on... Alex Adamyan Blog - While my keyboard gently weeps
We actually went a complete different with overriding the
DataAnnotationsMetadaDataProvider.
In there you can make sure that the DisplayNameAttribute values are resolved into the correct language.
Actually you could even get rid of that attribute and resolve by field names only if that would be any help.
I wrote this article a while ago. It uses a custom view engine.
http://blog.oimae.com/2011/02/20/cultured-view-engine-for-mvc/
And another tutorial for different solution
Tutorial: Create ASP.NET MVC localization with language detection