Handling exceptions in ASP.NET MVC is quite easy once you get to know the details surrounding the HandleError attribute. You can specify that a controller or a specific Action will handle errors and you can even choose which View to show based on the exception being thrown. Scott Guthrie wrote about this.
What he didn't tell us, is that there are some prerequisites for it to work as expected. First of all, you need to enable custom errors in the application web.config file:
<customErrors mode="On" />
Second, the order that you put the HandleError attributes will affect which View will actualy gonna be rendered at the end. I was trying to render a custom view based on an InvalidOperationException being throw on my action. The code looked like this:
1: [HandleError]
2: public class HomeController : QuavioController
3: {
4: [HandleError(ExceptionType = typeof(InvalidOperationException), View = "InvalidOpJoinRoom")]
5: public ActionResult JoinRoom()
6: {
7: throw new InvalidOperationException();
8: }
9: }
What happened is that the JoinRoom was returning the shared Error View, instead of the InvalidOpJoinRoom View. This happens because the HomeController contains a HandleError attribute (line 1), which overrides the JoinRoom's HandleError behavior (line 4), which should return the InvalidOpJoinRoom View.
The fix is very simple: Remove the HandleError atribute from the controller and let the actual actions define the proper error handling behavior.
Conclusion: Be aware that multiple HandleError attributes in a controller may alter the order which View evaluation is executed and then causing the final View not to be the view you were actually expecting.
I've been playing lately with ASP.NET MVC 2 Preview 2. I had no previous experience with this and it has been kind of a change in paradigms changing from web forms to mvc. At the same time, I feel very excited about this and believe that It is a big step forward when compared to web forms, mainly due to the separation of concerns and responsibilities.
As a drawback, It is very weird not to be able to drop ASP.NET server controls in the page. Initially, you'll feel a bit 'lost'. MVC uses a different method to render the page. You don't have the runat='server' stuff anymore so, instead, you'll have to render the page mostly based on what you have in your ViewData. It's not my objective to explain its functionality here, but you can find further information at the official MVC website. The latest release can be downloaded from CodePlex.
While testing my application in my hosting provider, I had a big headache since they have Windows 2003 Server installed, which comes with IIS 6. ASP.NET MVC requires a bit of work in order to work with IIS6, especially if your hosting provider does not have MVC installed in the GAC.
I would definitely suggest Phil Haack's blog as the first point for reference on this subject. There are two key posts regarding this issue that I followed in order to make it work.
First of all, MVC assembly needs to be deployed in the application Bin directory if it is not installed in the server. Detailed info here.
Second, you'll need to change the application routes for IIS 6 to correctly receive the requests and forward them to the controllers. Haacked.com walkthrough here.
As a last tip, I also found out that my MVC application wouldn't work if I used VS Publish tool to send it to the production server after following the two steps above. No clue why, but just copying the whole website files to the server worked fine. Weird!
CKEditor is a great open source wysiwyg editor for the web. It was formerly called FCKEditor and, one of its previous versions contained a nice implementation for ASP.NET integration. The current version (3.0) has been completely rebuilt from scratch and does not support quick upload yet (I read in the forums it will be available in version 3.1).
I've been using the FCKEditor 2.6.3 for .NET, which includes an ASP.NET control for seamless integration. However, I could never make one of its great features to work: the ability to upload images on the fly and embed them in the text. There are some things that need to be set up before.
1. FCKEditor config file (fckconfig.js), when you download it, comes with its connectors default language to php. You need to change it to aspx:
-
var _FileBrowserLanguage = 'aspx' ; // asp | aspx | cfm | lasso | perl | php | py
-
var _QuickUploadLanguage = 'aspx' ; // asp | aspx | cfm | lasso | perl | php | py
2. Configure the folder that contains the fckeditor scripts in FCKEditor.cs (You will need to create a virtual directory in IIS with this path):
[ DefaultValue( "/fckeditor/" ) ]
public string BasePath
3. Enable the upload connector in fckeditor\editor\filemanager\connectors\aspx\config.ascx (SECURITY WARNING: do not forget to implement authentication verification here!):
private bool CheckAuthentication()
{ return true; }
4. Configure the directory that will receive the uploaded images (same file as above) – This can be overriden in your website web.config appSettings section, creating a setting called FCKeditor:UserFilesPath
UserFilesPath = "/userfiles/";
This should be everything that is needed in order to make file upload to work. See ya!
[UPDATE]:
For those of you that saw this working fine in your development machine but unexplainably not working on the production server, please refer to this forum post for the fix.
[UPDATE 2]:
Another issue that I found regarding the update above is that in a server, it did not fix the problem an I was getting a 'permission denied' JS error on the window.parent.OnUploadCompleted event. If that happens, try this fix (scroll to the bottom of the page for the code)
