Easyui + asp.net MVC 系列教程 第19-23 節 完成注銷 登錄限制過濾 添加用戶


前面視頻 文章地址

 
這節課 我們要實現 一個登錄的限制

如果用戶沒有登錄 就訪問我們的管理頁面 那么 直接跳轉到登錄 當然 可以可以給一個中間的頁面 對用戶進行友好的提示

我們首先找到 管理頁的action
 
        public ActionResult Index()
        {
            return View();
        }

我們編寫一個過濾器 要繼承和實現一個接口

    public class CheckLoginFilter : FilterAttribute, IActionFilter
    {

        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (HttpContext.Current.Session["user"] == null)
            {
                filterContext.HttpContext.Response.Write("-1");
            }
        }

        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (HttpContext.Current.Session["user"] == null)
            {
               //filterContext.HttpContext.Response.Write("-1");
                try
                {
                    filterContext.Result = new RedirectResult("/Account/Login");
                }
                catch (Exception)
                {
                    filterContext.Result = new RedirectResult("/Common/Error");
                }
            }
        }
    }

然后 為管理員打上標記

        [CheckLoginFilter()]
        public ActionResult Index()
        {
            return View();
        }

用戶添加頁面的設計

<div id="tb" style="padding:5px;height:auto">

                <div style="margin-bottom:5px">
                        <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"></a>
                        <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true"></a>
                        <a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true"></a>
                        <a href="#" class="easyui-linkbutton" iconCls="icon-cut" plain="true"></a>
                        <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true"></a>
                </div>

                <div>
                        用戶名: <input type="text" id="name" style="width:80px">
                        密 碼: <input type="text" id="pwd" style="width:80px">
                        技 術: 
                        <select id="tec" class="easyui-combobox" panelHeight="auto" style="width:100px">
                                <option value="java">Java</option>
                                <option value="c">C</option>
                                <option value="basic">Basic</option>
                                <option value="perl">Perl</option>
                                <option value="python">Python</option>
                        </select>
                        <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="AddUser();">添加</a>
                </div>

        </div>

添加提交事件

function AddUser() {
    //$.messager.alert('Warning', '你真的添加嗎!');
    var name = $('#name').val();
    var pwd = $('#pwd').val();
    var tec = $('#tec').val();

    if (name == '' || pwd == '') {
        $.messager.alert('Warning', '用戶名或者密碼為空!');
    }
    else {
        $.post("/Account/AddUser", { name: name, name: pwd },
           function (data) {
               //alert("Data Loaded: " + data);
               if (data == '0') {
                   $.messager.alert('Warning', '添加失敗!');
               }
               else {
                   $.messager.alert('Warning', '添加成功!');
               }
           });
    }
}

高清錄屏下載地址

18-19節

http://pan.baidu.com/share/link?shareid=1882807484&uk=1731339785

20節

http://pan.baidu.com/share/link?shareid=473445811&uk=36858893

 

21-23節

http://pan.baidu.com/share/link?shareid=1857442884&uk=1731339785

需要源碼的:http://www.bamn.cn/thread-64-1-1.html?usersystem.rar


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM