我是一个菜鸟,我只是在努力,2021正视自己,面对2021!

把身份校验的头信息添加到响应头里面

 1.每天记录一点点

public class AuthorizeHelper 
{
    /// <summary>
    /// 把身份校验的头信息添加到响应头里面
    /// </summary>
    /// <param name="response"></param>
    /// <param name="viewModel"></param>
    public static void SetAuthInfoToCookie(HttpResponseBase     response, AdminViewModel viewModel)
    {
        HttpCookie cookie=new HttpCookie("auth");
        CustomerAuthentication cus = new CustomerAuthentication();
        cus.EmployeeId = viewModel.EmployeeId;
        cus.Tick = DateTime.Now.To1970MilinSeconds().ToString();
        cus.Verify = MD5Helper.MDString(viewModel.Password+cus.Tick);
        cookie.Value=JsonNet.SerializeToEntity(cus);
        response.Cookies.Add(cookie);
    }
}

public class CustomerAuthentication
{
    public string EmployeeId { get; set; }
    
    public string Tick { get; set; }

    public string Verify { get; set; }
}    

2.使用Jquery给HTTP表头添加信息
<head>
    <title>JavaScript给HTTP表头添加信息</title>
    <script src="/Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function SendAJAX() {
            $.ajax(
            {
                url: '/Test/GetAJAX',
                dataType: 'GET',
                data: { "id": 123 },
         //请求之前首先进行一些操作 beforeSend: function (e) { console.dir(e); console.log(e.setRequestHeader); e.setRequestHeader(
'salesMOUD-Authorization','uname-pwd-2012'); },
         //请求成功之后进行的而一些操作 success: function (d) { console.log(
'---------Ajax callback-----------'); console.log(d); } }); } </script> </head> <body> <input onclick="SendAJAX();" type="button" value="请求AJAX" /> </body>
posted @ 2013-09-23 09:30  Kencery  阅读(270)  评论(0)    收藏  举报
友情链接:初心商城