Skip to content

ASP.NET

ASP.NET MVC4笔记(一) 扩展Simplemembership

using System.Web.Mvc;

namespace MvcClassManageSystem.ActionFilters
{
    public class LogStateFilterAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            //string controller = filterContext.RouteData.Values["controller"].ToString();
            //string action = filterContext.RouteData.Values["action"].ToString();
            //System.Diagnostics.Debug.WriteLine("OnAction:" + controller + "/" + action);

            if (WebMatrix.WebData.WebSecurity.IsAuthenticated == true)
            {
                filterContext.Result = new RedirectToRouteResult(new System.Web.Routing.RouteValueDictionary(new { Controller = "Home", action = "Index" }));
            }
        }
    }
}

ASP.NET MVC 4笔记(二)

  1. 有Timestamp修饰的表在修改已有的记录是一定要将该字段复制,也就是说一定要在Edit网页里面添加一行: @Html.HiddenFor(model => model.RowVersion)
  2. WebSecurity.CreateAccount必须在Userprofile里面先创建账户。 System.Diagnostics.Debug.WriteLine("OnAction:" + controller + "/" + action);
  3. 转换string数组到int数组 int[] HostsList = Array.ConvertAll(Request["HostsId"].Split(','), u => int.Parse(u));