KES

Archive for the ‘MVC’ Category

There are two problems with Dot.Net
1. I love it and i can be a lot of fun coding in.
2. WordPress and php can do just about all of the same thing in about 1/3 the time.

Forcing to ssl/https in a controller action result is quite simple. All you need to do is add the [RequireHttps] attribute to the controller action. If you want to make an entire controller or an entire site do this it can become tedious.
Create a new custom attribute. Mark its target to Class and inheritable.


//#define ssl
using System;
using System.Web.Mvc;
namespace MyNameSpace.Controllers
{
    [AttributeUsage(AttributeTargets.Class, Inherited = true)]
    internal sealed class InheritableAttribute : Attribute { }

Now create a new class that extends Controller. Mark it Inheritable using that new attribute created above. This class is empty and its only purpose is to redirect all controller actions to https. Where this becomes handy is during testing on a local development server without ssl. Here I’m using a compiler directive exactly for this purpose.

   
[Inheritable]
#if ssl
    [RequireHttps]
#endif
    public class ControllerBaseController : Controller {}
}

To apply this to any or all controllers just do the following:


// dummy controler for dem
// inherit from your newly created BaseController just don’t try and name it BaseControler 
    public class CheckOutController : ControllerBaseController
    {
// …action 1,2,3. …
    }

I hope this helps some one
KES

Simple and to the point. This just plain works. If you ever wanted to send an email receipt using an existing (partial) view for the message body. This is it.

http://msug.vn.ua/blogs/bobasoft/archive/2010/01/07/render-partialview-to-string-asp-net-mvc.aspx

Don’t expect all the additional advice that you already know about.