As a Java guys who turn to .NET, I always look for some nice stuff in Java inside .Net’s. 

Java’s Servlet filter is something good, I think in ASP.NET the similar concept is httpmodule (correct me if I am wrong). Filter is a great place to implement authentication, logging, auditing, data compression, transcoding, data transforming (e.g. XSLT), …etc.

When I am planning to add OpenID into ASP.NET MVC application, I couldn’t find a good enough place to put the OpenID authentication codes.

ASP.NET’s form authentication mode should be able to work together with ASP.NET MVC, I already see a blog article talk about this. The only change is configure an action URL in the form action loginUrl . Monorails also suggested its user to use this way.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    ...
    <system.web>
        <authentication mode="Forms">
            <forms name="auth" loginUrl="auth/login">
            ...
            </forms>
        </authentication>

I wish ASP.NET MVC could also support something like MonoRails’ filter. MonoRails filters are executed before and|or after actions. It is useful for security, dynamic content and to keep away repetitive code.

Fortunately, on Controller class there are some virtual functions which enable we do something before, after the action:

protected virtual bool OnError(string actionName, MethodInfo methodInfo, Exception exception);
protected virtual void OnPostAction(string actionName, MethodInfo methodInfo);
protected virtual bool OnPreAction(string actionName, MethodInfo methodInfo);

We can the implement some of our own controller class, so we can make it easier to implement something like Java servlet filters (and its chain).

Still learning… so maybe I am not that right…



Leave a Comment