I'm new to ASP.NET MVC and I'm looking for the least painful way to get global error handling, logging, and reporting (via email) set up. FYI, my ASP.NET MVC app is being hosted as a web role in Azure, but I'm trying to avoid using any Azure-specific hooks.
It looks like getting ELMAH installed and configured is a good first step.
When I look in NuGet, I see:
ELMAH ("ELMAH with initial configuration for getting started quickly...")
Elmah.Contrib.Mvc ("...designed to add ease-of-use inside MVC projects...")
Elmah.MVC ("...painless integration into MVC...")
Which of these packages do I want to install?
EDIT: After some experimentation, I'm more confused. I compared the project files after installing each of the three options on top of a default MVC 4 app. It appears that neither Elmah.Contrib.Mvc nor Elmah.MVC add the elmah.1.2.2 package (which I get when I install basic ELMAH). Also, neither package adds the <elmah> section to Web.config.
So... do I need to install ELMAH first, and then install one of the "...MVC" packages to get whatever nifty improvements they presumably get me?
ELMAH - This is the default ELMAH package with no mvc specific code in it, if you dont do what is described here I don't believe ELMAH will log any errors that occur in you're controllers, and you may not be able to access the ELMAH log page
Elmah.Contrib.Mvc - This is an enhancement on ELMAH specifically for MVC based upon one of the creators of ELMAHS answer to a stack overflow question.
Elmah.MVC - This is simliar to the above package however I believe it provides much better support for mvc features like routes etc, It is also quite easy to install and configure, it removes a lot of the messing around you would have to do with ELMAH to take out various parts that arent required when running in a mvc project
You can read the authors posts to get a better idea of how it works:
Integrating ELMAH to ASP.NET MVC in right way
ELMAH MVC controller released on NuGet
ELMAH.MVC v.2.0.0 - Release Candidate
Personally I believe the last package would be the best one ot use, it seems to be the more up to date and maintained of the two mvc ones.
You might consider using Elfar instead of Elmah. Elfar is "inspired" by Elmah but is designed to be MVC specific and is very simple to configure.
Just open NuGet, and search for Elfar. You will find a number of different packages, but in general you want the one that conforms to the technology you are intested in using. I'm not familiar with Azure web roles, but if you have access to a standard Sql Server then you can simply use Elfar.SqlClient.
More info here:
https://github.com/stevenbey/elfar/wiki
Related
I am using OpenCover to cover a very simple ASP.NET MVC application. It's basically just a shell application: a handful of controller methods and not much else.
I am attempting to user OpenCover to launch an instance of IIS 8.0 Express, through which I will run the MVC application. However, when I try to browse to the site, I get an "Access is denied" 401.2 error. I have tried numerous things to solve this, mostly revolving around different ways to enable Windows Authentication. Most of my attempts have been based on advice from questions like this. Despite my efforts, I'm still getting this 401.2 error. Also, I should point out that when running this application through VS2013, I can access the site just fine.
One final detail is that in order to use OpenCover, I cannot use the full version of IIS because OpenCover and IIS don't work well together, so IIS Express is a must. If there is any sort of configuration details I can provide you with in order for you to better help me, please let me know. Thank you!
I'm creating an application with a .Net Web Api project wanting to use pure AngularJS as the client side. Since Web Api is built on top of MVC, it creates MVC specific and default items that I feel is not needed. These items include the HomeController, _ViewStart.cshtml, _layout.cshtml, etc. I tried removing them but it comes up with errors. Has anyone tried to remove the MVC stuff out of the web api project and used separate client side front-end? Is it even possible to remove the MVC items without errors?
Remove RouteConfig.cs from App_Start, remove the Views directory and all sub-directories including the Views internal web.config file. Comment out or delete all the lines in the Global.asax.cs Application_Start method except GlobalConfiguration.Configure(WebApiConfig.Register). Remove the HomeController, add an index.html and any needed Angular scripts and go at it. I also added solution folders to organize my views as reusing the existing Views folders did not work. I'm using VS 2015 but is should work for 2013 also. PWE
Web API is not built on top of MVC.
The default templates bring in MVC for the sake of supporting a help page, but you don't need to use it.
You can start with an empty web project and just check Web API.
The routing piece is server routing and it's part of what maps the URL to Controllers+Actions, it has nothing to do with Angular routing.
As Mike Cheel alluded to, there are no dependencies between MVC and Web API. However, if you use the built-in templates, it's easy to get the impression that the 2 are linked. They include a lot of stuff in these templates because they can't anticipate where you want to go with your project... so they try to cover all the bases.
For your purposes, you would probably be better off to start with an empty project and add only the components that you actually need. For this approach, some of the best tutorials and starter projects are from Taiseer Joudeh's "Bit of Technology" blog. His tutorials helped me to build an "MVC Free" web application from scratch that uses JSON Web Tokens and AngularJS Interceptors for security and Web API 2 and Entity Framework to serve up the data.
He has many tutorials on his website... but you might want to start with "AngularJS Token Authentication using ASP.NET Web API 2, Owin, and Identity". What what.. you didn't ask about security? Well... security is an issue that you will need to confront at some point anyway... and Taiseer presents a nice solution for securing an Angular/Web API application.
I've found plenty of questions / blog posts about this, but I have not seen a repeatable recipe for getting an MVC site running on Mono. Nor have I been able to, after many hours of attempts, been able to get an MVC site to run on Mono.
I can spin up whatever version of whatever distribution is required, and can use either MVC3 or MVC4. I would prefer to use nginx, but can use mod_mono as well. I can build from source or use packages.
Can anyone give a step-by-step on getting MVC to run on Mono?
Example Error
This is what I get when I try to run a barebones app on fastcgi or xsp:
Missing method .ctor in assembly
/tmp/root-temp-aspnet-0/eaee30a1/assembly/shadow/bef1c25f
/a2978c47_1c664e18_00000001/System.Web.Providers.dll,
type System.Data.Objects.DataClasses.EdmRelationshipAttribute
Can't find custom attr constructor image:
/tmp/root-temp-aspnet-0/eaee30a1/assembly/shadow/bef1c25f
/a2978c47_1c664e18_00000001/System.Web.Providers.dll mtoken: 0x0a000012
It's very easy. Use MonoDevelop IDE http://monodevelop.com/.
Check this page http://www.integratedwebsystems.com/2011/06/get-mvc3-razor-running-on-mono/
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.
Long time lurker, first time poster. I'm a self-taught hacker that learned Ruby on Rails to start. At work I've been allowed to work on a web app--the only catch is I have to use ASP.NET. This technology choice is mandated, as much as I'd prefer to use Rails.
There's dozens of "Rails for .NET/PHP/Java Developers" books and blog posts but I haven't found any going the opposite direction, from Rails to .NET.
Could someone please give me an overview of how a typical Rails app would translate over to ASP.NET MVC? I'll research the details of the IDE, C#/VBscript, etc. But what are the possible equivalents to:
Generators
Gems/Plugins
Databases
Migrations
Routes
Models (ORMs)
Controllers (InheritedResources)
Views (layouts, templates, partials)
Rails Console
Test Units/Specs
etc. anything else I'm forgetting
I assume a lot of the Rails niceties I take for granted like route-based helper methods, and simple macro association declarations will not be possible. :(
Thank you so much!
I think what you'll find in the .Net world is that you have a lot of choices to make. Rails is nice because it provides all of that stuff in one place, but developing for .Net you'll have to piece together a solution of your own.
Generators - There are various code generation facilities, but each one is for a different piece. Eg, you can get MyGeneration that will generate code based on a database.
Gems/Plugins - No uniting system for this; Components can be found on the web and you would download either the source or the .dll, then you would add a reference in your project to the assembly (.dll).
Databases - you can connect to pretty much anything; You'll probably find the most guidance for an MS SQL Server.
Migrations - I don't know of a direct method for this in the .net world; I usually write SQL code in SQL and run scripts on the server manually as part of deployment.
Routes - ASP.Net MVC includes routes, look in the global.asax.cs file that gets generated when you create a project for example.
Models (ORMs) - ORMs for .Net are all over the place. Included as part of .Net are things like Linq-to-sql and the Entity Framework. Outside of MS you can find many, but I'd probably recommend NHibernate.
Controllers - Built in to .Net MVC; You get to write the code.
Views - Built in to .Net MVC; Once again you get to write them. MasterPages allow you to get the same general layout on all your pages(including common header/footer, etc), Web Controls (.ascx files) allow you to do a partial view.
Rails Console - I don't know exactly what this provides (I'm a .net developer interested in learning Rails, but haven't spent much time yet); Visual Studio lets you debug applications, step through code, etc. I don't think there are any consoles available to test code outside of just writing the code, compiling, and running it.
Test Units/Specs - There are a few test frameworks for .Net (MS has a framework included, NUnit is one alternative). For specs and such, probably google around for Behavior Driven Design and see what exists.
There are a couple of .NET ports of RoR migrations. I have used migratordotnet and FluentMigrator. Both work as expected but I prefer FluentMigrator. It is more full-featured (e.g. can create indexes) and I like the fluent style.
LINQPad is your equivalent to Rails Console.. see here:
https://stackoverflow.com/a/9403457/1029644
You should download Visual Studio 2008 Express, and download ASP.NET MVC 1.0 (I wouldn't download ASP.NET MVC 2.0 yet because it's only in RC. Wait until it hits 2.0 final).
You can also check out the Nerddinner walkthrough. It's very helpful when learning ASP.NET MVC.
Generators
Do you mean code generators? Ew.
Gems/Plugins
If you want functionality, you can either build it or see if a JQuery plugin exists for it.
Databases
The Database is accessed through your model.
Migrations
?
Routes
Routing is handled by the framework, and you can add routes in the Global.asax.cs file.
Models (ORMs)
Models are indeed still called 'Models', and in ASP.NET MVC, if you use LINQ-To-SQL, the model is generated for you when you drag your database tables in. You can use the Repository pattern to access the database model.
Controllers (InheritedResources)
Controllers are still called controllers.
Views (layouts, templates, partials)
There are different types of View Engines, but the one provided with ASP.NET MVC should do well at first.
Rails Console
I'm guessing you mean the IDE/Debugger? You can build and debug an ASP.NET MVC app inside of Visual Studio.
Test Units/Specs
You can use NUnit, or you can use MSUnit. MSUnit is already integrated with Visual Studio, but NUnit can be.