mvc 小计

使用mvc 小计

1.关于页面{
[mvcapplication模式]
csthml=”需要一个新的control类对应否则访问会找不到(为什么会这样呢 因为每个页面的呈现都需要经过control类的逻辑处理)”,
“RenderPatial RenderAction 区别 “=”RenderPatial的数据来自于调用的View,而RenderAction来自自己。[取于其他人总结]”,
“RenderPatial RenderAction 区别 “=”RenderAction会发起一个新的Request,而RenderPatial不会。[取于其他人总结
详情参考 csdn死对头
http://www.cnblogs.com/gesenkof99/archive/2013/06/03/3115052.html
]”,
}

2.关于页面控件{
[呈现html控件]
@Html.LabelFor(m => m.name) = “显示[Display] 的内容”,
@Html.Label(m => m.mypwd)=“显示model属性的值”,
@Html.ValidationMessageFor(m=>m.name) =”如果要显示验证信息需要加上这个”,
}

3.关于控制{
身份
[AllowAnonymous] =”身份验证需要配置web.config[



]”,
自定义验证=”重写ActionFilterAttribute[

public class IsLogin : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
bool isLogin = false;

        //用MVC系统自带的功能 获取当前方法上的特性名称
        bool skipAuthorization = filterContext.ActionDescriptor.IsDefined(typeof(NoNeedLogin), inherit: true)
                                 || filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(NoNeedLogin), inherit: true);

        if (skipAuthorization)
        {
            return;
        }

        //检查是否登录
        AdminBll adminBll = new AdminBll();
        if (!adminBll.IsLogin())
        {
            //强制调转实现身份验证
            filterContext.HttpContext.Response.Redirect("http://" + filterContext.HttpContext.Request.Url.Authority + "/Admin/Login");
        }
    }
}

 //忽略身份验证
 public class NoNeedLogin : Attribute{ }

 //验证
 [IsLogin]
public class AdminController : BaseController
{

    //登录 表单(忽略验证)
    [NoNeedLogin]
    public ActionResult Login()
    {
        return View();
    }

]”

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值