Popular Posts
Enable SSL connection for Jsoup import org.jsoup.Connection; import org.jsoup.Jsoup; import javax.net.ssl.*; import java.io.IOException; import java.security.KeyManagement... Word break tag : <wbr/> (HTML5) The  HTML  <wbr>  tag  is  used  defines  a  potential  line  break  point  if  needed.  This  stands  for  Word  BReak. This  is  u... Build an OpenVPN server on android device Preparation An android device, in this case, Sony xperia Z is used Root permission required Linux Deploy for deploy i...
Stats
Action results
  • ActionResult

    Encapsulates the result of an action method and is used to perform a framework-level operation on behalf of the action method.
    public ActionResult Index()
    {
        return Show();
    }
    
    public ActionResult Show()
    {
        return View();
    }
    
  • ContentResult

    Represents a user-defined content type that is the result of an action method.
    public ActionResult Index()
    {
        return Content("Represents a user-defined content type that is the result of an action method.", "text/plain", System.Text.Encoding.UTF8);
    }
  • EmptyResult

    Represents a result that does nothing, such as a controller action method that returns nothing.
    public ActionResult Index()
    {
        return new EmptyResult();
    }
  • FileContentResult

    Sends the contents of a binary file to the response.
    public ActionResult Index()
    {
        //return new FileContentResult(Buffer, "application/pdf");
        return File(Buffer, "application/pdf");
    }
  • FilePathResult

    Sends the contents of a file to the response.
    public ActionResult Index()
    {
        return File(Server.MapPath("~/doc/sample.pdf"), "application/pdf");
    }
  • FileStreamResult

    Sends binary content to the response by using a Stream instance.
    public ActionResult Index()
    {
        using (var ms = new System.IO.MemoryStream())
        {
            TempImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            //return new FileStreamResult(ms, "image/png") { FileDownloadName = "logo.png" };
            return File(ms, "image/png", "logo.png");
        }
    }
  • HttpNotFoundResult

    Defines an object that is used to indicate that the requested resource was not found.
    public ActionResult Index()
    {
        return HttpNotFound("Page not fould");
    }
  • HttpStatusCodeResult

    Provides a way to return an action result with a specific HTTP response status code and description.
    public ActionResult Index()
    {
        return new HttpStatusCodeResult(System.Net.HttpStatusCode.Unauthorized);
    }
  • HttpUnauthorizedResult

    Represents the result of an unauthorized HTTP request.
    public ActionResult Index()
    {
        return new HttpUnauthorizedResult("Please sign in");
    }
  • JavaScriptResult

    Sends JavaScript content to the response.
    public ActionResult Index()
    {
        return JavaScript("alert(new Date());");
    }
  • JsonResult

    Represents a class that is used to send JSON-formatted content to the response.
    public ActionResult Index()
    {
        return Json(new { Message = "Represents a class that is used to send JSON-formatted content to the response." });
    }
  • PartialViewResult

    Represents a base class that is used to send a partial view to the response.
    public ActionResult Index()
    {
        return PartialView();
    }
  • RedirectResult

    Controls the processing of application actions by redirecting to a specified URI.
    public ActionResult Index()
    {
        //return Redirect("/Product");  // 302
        return RedirectPermanent("/Product");  // 301
    }
    Redirect and RedirectPermanent
  • RedirectToRouteResult

    Represents a result that performs a redirection by using the specified route values dictionary.
    public ActionResult Index()
    {
        //return RedirectToAction("Show");
        //return RedirectToActionPermanent("Show");
        //return RedirectToRoute(new { action = "Show" });
        return RedirectToRoute(new { action = "Show" });
    }
  • ViewResult

    Represents a class that is used to render a view by using an IView instance that is returned by an IViewEngine object.
    public ActionResult Index()
    {
        return View();
    }
Action attributes
  • AcceptVerbsAttribute

    Represents an attribute that specifies which HTTP verbs an action method will respond to.
    [AcceptVerbs(HttpVerbs.Get)]
    public ActionResult Index() { return View(); }
    [AcceptVerbs("get", "post")]
    public ActionResult Index() { return View(); }
  • ActionFilterAttribute

    Represents the base class for filter attributes.
    public class PermissionFilterAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            base.OnActionExecuted(filterContext);
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
        }
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            base.OnResultExecuted(filterContext);
        }
        public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            base.OnResultExecuting(filterContext);
        }
    }
  • ActionMethodSelectorAttribute

    Represents an attribute that is used to influence the selection of an action method.
    public class RequestSourceFilterAttribute : ActionMethodSelectorAttribute
    {
        public override bool IsValidForRequest(ControllerContext controllerContext, System.Reflection.MethodInfo methodInfo)
        {
            throw new NotImplementedException();
        }
    }
  • ActionNameAttribute

    Represents an attribute that is used for the name of an action.
    [ActionName("Substitute")]
    public ActionResult Index() { return View(); }
  • ActionNameSelectorAttribute

    Represents an attribute that affects the selection of an action method.
    public class RequestSourceFilterAttribute : ActionNameSelectorAttribute
    {
        public override bool IsValidName(ControllerContext controllerContext, string actionName, System.Reflection.MethodInfo methodInfo)
        {
            throw new NotImplementedException();
        }
    }
  • AllowHtmlAttribute

    Allows a request to include HTML markup during model binding by skipping request validation for the property. (It is strongly recommended that your application explicitly check all models where you disable request validation in order to prevent script exploits.)
    [AllowHtml]
    public ActionResult Index() { return View(); }
  • AsyncTimeoutAttribute

    Represents an attribute that is used to set the timeout value, in milliseconds, for an asynchronous method.
    [AsyncTimeout(1000000)] // In milliseconds.
    public ActionResult Index() { return View(); }
  • AuthorizeAttribute

    Represents an attribute that is used to restrict access by callers to an action method.
    [Authorize(Users = "Betty, Johnny", Roles = "Admin, Super User")]
    public ActionResult Index() { return View(); }
    public class ApplicationAuthorizaeAttribute : AuthorizeAttribute
    {
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            return base.AuthorizeCore(httpContext);
        }
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            base.HandleUnauthorizedRequest(filterContext);
        }
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.OnAuthorization(filterContext);
        }
        protected override HttpValidationStatus OnCacheAuthorization(HttpContextBase httpContext)
        {
            return base.OnCacheAuthorization(httpContext);
        }
    }
  • ChildActionOnlyAttribute

    Represents an attribute that is used to indicate that an action method should be called only as a child action.
    [ChildActionOnly]
    public ActionResult Index() { return View(); }
    @{Html.RenderAction("Index");}
  • FilterAttribute

    Represents the base class for action and result filter attributes.
    public class BaseFileter : FilterAttribute
    {
        public override bool IsDefaultAttribute()
        {
            return base.IsDefaultAttribute();
        }
        public override bool Match(object obj)
        {
            return base.Match(obj);
        }
    }
  • HandleErrorAttribute

    Represents an attribute that is used to handle an exception that is thrown by an action method.
    [HandleError(Master = "Site", View = "Error", ExceptionType = typeof(NullReferenceException))]
    public ActionResult Index() { return View(); }
  • HttpDeleteAttribute

    Represents an attribute that is used to restrict an action method so that the method handles only HTTP DELETE requests.
    [HttpDelete]
    public ActionResult Index() { return View(); }
  • HttpGetAttribute

    Represents an attribute that is used to restrict an action method so that the method handles only HTTP GET requests.
    [HttpGet]
    public ActionResult Index() { return View(); }
  • HttpPostAttribute

    Represents an attribute that is used to restrict an action method so that the method handles only HTTP POST requests.
    [HttpPost]
    public ActionResult Index() { return View(); }
  • HttpPutAttribute

    Represents an attribute that is used to restrict an action method so that the method handles only HTTP PUT requests.
    [HttpPut]
    public ActionResult Index() { return View(); }
  • NonActionAttribute

    Represents an attribute that is used to indicate that a controller method is not an action method.
    [NonAction]  // Prevent called from url
    public void InnerCall() { Response.Write("Hello InnerCall"); Response.End(); }
  • OutputCacheAttribute

    Represents an attribute that is used to mark an action method whose output will be cached.
    [OutputCache(Duration = 60, VaryByParam = "page")]
    public ActionResult Index() { return View(); }
  • RequireHttpsAttribute

    Represents an attribute that forces an unsecured HTTP request to be re-sent over HTTPS.
    [RequireHttps]
    public ActionResult Index() { return View(); }
  • SessionStateAttribute

    Specifies the session state of the controller.
    [SessionState(System.Web.SessionState.SessionStateBehavior.Required)]
    public ActionResult Index() { return View(); }
  • ValidateInputAttribute

    Represents an attribute that is used to mark action methods whose input must be validated.
    [ValidateInput(false)]
    public ActionResult Index() { return View(); }
Customize facebook share content
<html>
<head>
    <title>Custimize share content to FB</title>
    <!-- Customize share title -->
    <meta name="title" content="Shared content Title" />
    <!-- Customize share description -->
    <meta name="description" content="Shared content description" />
    <!-- Customize share image -->
    <link rel="image_src" href="https://lh3.googleusercontent.com/-UOMvCNsu6MA/Tgu_o7_JFaI/AAAAAAAAB04/tt7bnHTv4aY/s296-no/QR_http___nanashi07_blogspo.png" />
</head>
<body>
    <a href="https://www.facebook.com/sharer/sharer.php?src=bm&u=http://nanashi07.blogspot.com">Share this page to FB</a>
</body>
</html>
or
<html>
<head>
    <title>Custimize share content to FB</title>
    <!-- Customize share title -->
    <meta property="og:title" content="Shared content Title" />
    <!-- Customize share description -->
    <meta property="og:description" content="Shared content description" />
    <!-- Customize share image -->
    <meta property="og:image" content="https://lh3.googleusercontent.com/-UOMvCNsu6MA/Tgu_o7_JFaI/AAAAAAAAB04/tt7bnHTv4aY/s296-no/QR_http___nanashi07_blogspo.png" />
    <!-- Customize share url -->
    <meta property="og:url" content="http://nanashi07.blogspot.com" />
    <!-- Customize share image -->
    <link href="https://lh3.googleusercontent.com/-UOMvCNsu6MA/Tgu_o7_JFaI/AAAAAAAAB04/tt7bnHTv4aY/s296-no/QR_http___nanashi07_blogspo.png" rel="image_src" type="image/jpeg" /
</head>
<body>
    <a href="https://www.facebook.com/sharer/sharer.php?src=bm&u=http://nanashi07.blogspot.com">Share this page to FB</a>
<body>
</html>
pushState & ajax page loading
Index.cshtml
<html>
<head>
    <title></title>
    <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
    <style>
        #root-container {
            margin: 20px;
        }
    </style>
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
    <script>
        $(function () {
            $('.nav li a').click(function () {
                $(this).parentsUntil('#root-container').last().children().removeClass('active');

                var $url = $(this).attr('href');
                $.ajax({
                    url: $url,
                    type: 'POST',
                    success: function ($data) {
                        $('#tab-container').html($data);
                    }
                });

                if (location.pathname != $url) {
                    window.history.pushState({ path: $url }, $(this).text(), $url);
                }

                $(this).parent().addClass('active');
                return false;
            });

            $('.nav li a').each(function () {
                if (location.pathname == $(this).attr('href')) {
                    $(this).click();
                    return false;
                }
            });

            if ($('.nav li.active').size() == 0) {
                $('.nav li a').first().click();
            }
        });
    </script>
</head>
<body>
    <input type="hidden" id="current-path" value="@ViewBag.CurrentPath" />
    <div id="root-container">
        <ul class="nav nav-tabs">
            <li><a href="~/Home/jQuery">What is jQuery?</a></li>
            <li><a href="~/Home/jQueryUI">jQueryUI</a></li>
            <li><a href="~/Home/Bootstrap">Bootstrap</a></li>
        </ul>
        <div id="tab-container"></div>
    </div>
</body>
</html>
HomeController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcApplication1.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.CurrentPath = Request.Url.AbsolutePath;
            return View();
        }

        public ActionResult jQuery()
        {
            switch (Request.HttpMethod)
            {
                case "POST":
                    return View();
                default:
                    return View("Index");
            }
        }

        public ActionResult jQueryUI()
        {
            switch (Request.HttpMethod)
            {
                case "POST":
                    return View();
                default:
                    return View("Index");
            }
        }

        public ActionResult Bootstrap()
        {
            switch (Request.HttpMethod)
            {
                case "POST":
                    return View();
                default:
                    return View("Index");
            }
        }
    }
}

Reference: Manipulating the browser history