Thursday, December 13, 2012

HTTP Basic Authentication against Non-Windows Accounts in IIS/ASP.NET (Part 2 – The HTTP Module)

Ref: http://leastprivilege.com/2008/01/12/http-basic-authentication-against-non-windows-accounts-in-iisasp-net-part-2-the-http-module/

Sunday, August 12, 2012

ActionResult Vs ViewResult


1. ActionResult is an abstract class, and it's base class for ViewResult class.
2. In MVC framework, it uses ActionResult class to reference the object your action method returns. And invokes ExecuteResult method on it.
3. It's usually a good practice to have your method return a more specific class. So if you are sure that your action method will return some view page, you can use ViewResult. But if your action method may have different behavior, like either render a view or perform a redirection. You can use the more general base class ActionResult as the return type.
4. You can absolutely use specific return types, even though most examples on the web seems to return the ActionResult. The only time I would return the ActionResult class is when different paths of the action method returns different subtypes.
5.

6. Steven Sanderson also recommends returning specific types in his book Pro ASP.NET MVC Framework. Take a look at the quote below:

"This action method specifically declares that it returns an instance of ViewResult. It would work just the same if instead the method return type was ActionResult (the base class for all action results). In fact, some ASP.NET MVC programmers declare all their action methods as returning a nonspecific ActionResult, even if they know for sure that it will always return one particular subclass. However, it's a well-established principle in object-oriented programming that methods should return the most specific type they can (as well as accepting the most general parameter types they can). Following this principle maximizes convenience and flexibility for code that calls your method, such as your unit tests."

Saturday, August 11, 2012

ViewResult


ViewResult derives from ActionResult.

ActionResult types available


ActionResult
The action result is a very generic return value for an action. This is because it is the abstract base class for other types of actions. It is actually a very simple class having only one method that needs implementing.



public abstract class ActionResult
{
    public abstract void 
        ExecuteResult(ControllerContext context);
}




Inheriting from the ActionResult are the following classes:

ContentResult
EmptyResult
FileResult
HttpStatusCodeResult
JavaScriptResult
RedirectResult
RedirectToRouteResult
ViewResultBase

These are the classes that inherit from ActionResult indirectly:

FileContentResult
FilePathResult
FileStreamResult
HttpNotFoundResult
HttpUnauthorizedResult
PartialViewResult
ViewResult


ActionResult is an abstract class that can have several subtypes:

a) ViewResult - Renders a specifed view to the response stream

b) PartialViewResult - Renders a specifed partial view to the response stream

c) EmptyResult - An empty response is returned

d) RedirectResult - Performs an HTTP redirection to a specifed URL

e) RedirectToRouteResult - Performs an HTTP redirection to a URL that is determined by the routing engine, based on given route data

f) JsonResult - Serializes a given ViewData object to JSON format

g) JavaScriptResult - Returns a piece of JavaScript code that can be executed on the client

h) ContentResult - Writes content to the response stream without requiring a view

i) FileContentResult - Returns a fle to the client

j) FileStreamResult - Returns a fle to the client, which is provided by a Stream

k) FilePathResult - Returns a fle to the client