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<string, int>(Request["HostsId"].Split(','), u => int.Parse(u));
    

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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" }));
            }
        }
    }
}