background preloader

AspNetMvc

Facebook Twitter

C# - Web API in MVC solution in separate project. Asp.net mvc - How to serve html file from another directory as ActionResult. Asp.net mvc - Is it OK to put JavaScript in Partial Views. Html - How to detect which submit button was clicked in asp.net (mvc) Home : The Official Microsoft ASP.NET Site. Routing - Image equivalent of ActionLink in ASP.NET MVC. Home : The Official Microsoft ASP.NET Site. Asp.net mvc - how to run scheduler utility in web application. Asp.net mvc - How to serve html file from another directory as ActionResult. Asp.net mvc - Is it OK to put JavaScript in Partial Views.

Handling Errors Effectively in ASP.NET MVC. ASP.NET MVC gives you more options in the way that you handle exceptions.

Handling Errors Effectively in ASP.NET MVC

Error handling isn't intrinsically exciting, but there are many ways of avoiding the classic yellow page of death, even getting ELMAH to manage error handling for you. Years ago, ASP.NET’s error handling was one of the major things that made me wonder if ASP.NET MVC could give me something that ASP.NET Web Forms couldn’t. Web Forms is based on pages; so if something goes wrong, all that you can do is to redirect the user to another page and explain what the error was or just be generically sorry. ASP.NET Web Forms allow you to map an error page for each possible HTTP status code. You control the mapping through the <customErrors> section of the web.config file. Because of the different architecture of the view in ASP.NET MVC, it is possible to save the redirect command and then programmatically switch to an error view in the context of the same request.

[HandleError] public class HomeController { ... } Asp.net mvc - How to serve html file from another directory as ActionResult. How to: Implement Remote Validation in ASP.NET MVC. Home : The Official Microsoft ASP.NET Site. Asp.net mvc - How to serve html file from another directory as ActionResult. Asp.net mvc - MVC3 : How to redirect to html page from a class which handles the errors. Asp.net mvc 4 - Can a 'ViewModel' hold 'DomainModel' type property. Asp.net mvc - MVC unobtrusive range validation of dynamic values. Siraj Tech Solutions. ASPNET MVC. C# - DropDownListFor for a complex model having problems validating. Razor - In MVC 4 assign client side DropDown value to Model Property on Submit.

Asp.net mvc 4 - Entity Framework 5 Unit of Work pattern - where should I call SaveChanges. Asp.net mvc - Repository With UnitOfWork pattern for database in MVC application. ASP.NET MVC - repository pattern + unit of work pattern for database connection. C# - MVC3 data is not collected from partial view. C# - Would like to execute a query once per day in ASP.NET MVC. Routes - how to get a parameter from dynamic url in asp.net MVC4. JS in MVC partial views. Validation - Escape Certain Characters On Model Property in ASP.NET MVC. Asp.net mvc - Html.DropDownListFor in Editor Template not setting selected value. C# - How can we take a short description from a long description in asp.net mvc3 using LINQ. C# - Provide a custom error page for 401 (failed authorization) Asp.net mvc - Strange behavior in helper method DropDownListFor. Asp.net mvc - how to run scheduler utility in web application. .net - Redirect error when using custom AuthorizeAttribute on MVC4 Controller.

ASP.NET MVC - How to maintain correct model binding behaviour when passing model property to partial view. ASP.NET MVC Serving html file instead of a view from another directory. Asp.net mvc - DisplayName attribute from Resources. .net - ViewData of Actionfilter is not available in Base Controller property. .net - ViewData of Actionfilter is not available in Base Controller property. Telerik MVC grid - refresh foreign key dropdown list. Asp.net mvc - Dealing with Enums in Asp MVC Telerik Grid and Entity Framework. Asp.net mvc - Entity framework: Where & enum. Uploadify - asp.net mvc large file upload. Asp.net mvc - Html.EditorFor with shortDateTostring. Asp.net mvc - MVC: How to use (render) sections from parent (master) View (Layout View) C# - Is ASP.NET MVC 3 ready for business applications. C# - Newbie performance issue with foreach ...need advice.

User friendly CAPTCHA for Asp.Net MVC. In this post I will show you how to add CAPTCHA functionality to a html form in an Asp.Net MVC 4 project.

User friendly CAPTCHA for Asp.Net MVC

My goal is to make the CAPTCHA problem easy enough for all to solve, like a simple sum operation, and easier to read then the standard CAPTCHA text. An easy to read image is more vulnerable to smart bots that have an ORC system but I prefer to scare less clients then to provide the strongest anti-bot protection. And one more feature, when clicked the image should, change giving the users a new chance to respond correctly. Implementing CAPTCHA in C# and MVC 4 takes these steps: Create an Action that returns a CAPTCHA image and stores in the user session the right answer Add to your Model a string property named Captcha Add to your View the textbox for Captcha and the image placeholder Validate answer inside your own Action Render CAPTCHA image CaptchaController.cs publicActionResult CaptchaImage(string prefix, bool noisy = true) {var rand = newRandom((int)DateTime.Now.Ticks);

ASP.NET WebAPI: Getting Started with MVC4 and WebAPI. Download source code - 2.81 MB Introduction I’ve spent the last year working on ASP.NET MVC3 and feeling good this year on MVC4.

ASP.NET WebAPI: Getting Started with MVC4 and WebAPI

I got some new exciting features after updating to MVC4, Web API is one of those exciting features. I have read a lot on this feature and have read a lot of good articles on the web. But I didn't get any article that covers all the concepts in one place. Conditional Attributes in Razor View Engine and ASP.NET MVC 4. ASP.NET MVC 4 and the Razor View Engine v2 were released in beta awhile back with some pretty nice features like ASP.NET MVC 4 Bundling and Minification, EF Data Migrations, and ASP.NET Web API.

Conditional Attributes in Razor View Engine and ASP.NET MVC 4

You can find all of this in my ASP.NET MVC 4 Tutorials. The new Razor View Engine v2 has a couple of nice features, too, like the new "Tilde Slash" feature that avoids the use of Url.Content and Href to convert relative paths to absolute paths. Another nice feature I want to mention in Razor are conditional attributes, which simplify the code you need to write to include attributes on various HTML tags in your Razor Views. EFMVC - ASP.NET MVC 4, Entity Framework 4.3 Code First and Windows Azure. Home. 6 Ways To Avoid Mass Assignment in ASP.NET MVC. One of the scenarios that I always demonstrate during an ASP.NET MVC class is how to create a mass assignment vulnerability and then execute an over-posting attack.

6 Ways To Avoid Mass Assignment in ASP.NET MVC

It is a mass assignment vulnerability that led to a severe problem on github last week. Let's say you have the following model. public class User { public string FirstName { get; set; } public bool IsAdmin { get; set; } } When you want to let a regular user change their first name, you give them the following form. @using (Html.BeginForm()) { @Html.EditorFor(model => model.FirstName) <input type="submit" value="Save" /> } There is no input in the form to let a user set the IsAdmin flag, but this won't stop someone from crafting an HTTP request with IsAdmin in the query string or request body.

If you use the MVC model binder with the above request and the previous model, then the model binder will happily move the IsAdmin value into the IsAdmin property of the model. Using MEF with MVC Controllers - var Matt = new Hero(); I’ve recently been introduced to the Managed Extensibility Framework by a colleague at work, and have enjoyed picking it up so much it made me wonder how I could apply the simplicity of composition into my favourite web framework, ASP.NET MVC.

Using MEF with MVC Controllers - var Matt = new Hero();

There are a few obstacles to overcome initially, namely how instances are composed by default, and how the MVC system handles custom controllers. The idea behind this project, is to enable a Controller to be developed and deployed in it’s own assembly, with the ability to drop it into a project as an extension. Thus, as is the nature of MEF, this was down to exports and imports. MVC allows us to customise how controllers are created by implementing our own controller factory, so we can use this as well. This initial problem with how MEF would work with MVC controllers, is that a controller is created when it is needed, not composed (and instantiated) straight away. Modular ASP.NET MVC using the Managed Extensibility Framework (MEF), Part One - var Matt = new Hero(); Building on the work I have done previous (see Using MEF with MVC Controllers), I’ve created a revised architecture of MEF + MVC using .NET 4.0.

Modular ASP.NET MVC using the Managed Extensibility Framework (MEF), Part One - var Matt = new Hero();

I’m (mostly) happy with the outcome. One of the things I wanted to get right, was allowing true modularity using MEF. As you already know, its now relatively painless to do modular code with ASP.NET (thanks to standard .NET activation, or using something like MEF for automatic composition), but one of the challenges is not how the code plugs in, but the views themselves. This was always difficult with WebForms because of the way the .aspx pages are compiled (seperately from the code).

The other pain is the way you may have had to organise your files in the file system, they were also disconnected from the libraries because these had to exist in the \bin directory of your application. Extensible MVC with MEF can address these: So, how do we go about making a truly modular MVC implementation? Public class Application : HttpApplication { Modular ASP.NET MVC using the Managed Extensibility Framework (MEF), Part Two - var Matt = new Hero();

In my previous post I presented an MVC Framework that uses the Managed Extensibility Framework (MEF) to allow for powerful extensibility of ASP.NET MVC, not just for controllers, but also for views.

Modular ASP.NET MVC using the Managed Extensibility Framework (MEF), Part Two - var Matt = new Hero();

You can find my original article here. There are a couple of small issues I want to iron out before it becomes a project-quality framework. These issues are: Strongly-typed Models from imported librariesManaging referenced libraries in built modules Strongly-typed Models from imported libraries In the previous version of the framework, one thing which I had neglected to highlight and test is using a strongly-typed view model from an external module. This is quite a common occurence, and is due to the MVC framework not being able to instantiate the types required to process the views. Ok, thats done, what next: Modular ASP.NET MVC using the Managed Extensibility Framework (MEF), Part Three - var Matt = new Hero(); Firstly, sorry it’s been so long since my last MVC+MEF post, been a bit busy with life in general.

Modular ASP.NET MVC using the Managed Extensibility Framework (MEF), Part Three - var Matt = new Hero();

Still haven’t managed to get my project onto CodePlex, but we shall see soon! Ok, so where did we get to last time? We’ve managed to build a prototype MVC+MEF framework that supports modular areas and strongly-typed views. A couple of readers have been asking how we can incorporate IoC into our framework, and the question is really: do we need to?

This framework was originally conceived as a starting point for building a web application, so we could essentially allow MEF do handle our DI for us. The good news is there is a way, and it’s rather easy. The CSL project is geared to providing a common abstraction over service location (i.e. accessing and instantiating types, regardless of which third-party IoC container you are using).