コード例 #1
0
        public ActionResult Index(string User, string Pass)
        {
            LoginModel dat = new LoginModel();
            dat.User = User;
            dat.Pass = Pass;

            var request = (HttpWebRequest)WebRequest.Create("http://localhost:1844/api/Login");
            //var request = (HttpWebRequest)WebRequest.Create("http://amishsthapit.com.np/api/Login");
            string postData = JsonConvert.SerializeObject(dat);

            byte[] buf = Encoding.UTF8.GetBytes(postData);
            request.Method = "POST";
            request.ContentType = "application/JSON";
            request.ContentLength = buf.Length;
            request.GetRequestStream().Write(buf, 0, buf.Length);
            var response = (HttpWebResponse)request.GetResponse();
            var encoding = ASCIIEncoding.ASCII;
            using (var reader = new System.IO.StreamReader(response.GetResponseStream(), encoding))
            {
                string responseText = reader.ReadToEnd();

                if (Boolean.Parse(responseText))
                {
                    Session["User"] = dat.User;
                    return (RedirectToAction("Home"));
                }
                else
                    return View();
            }
        }
コード例 #2
0
        public Boolean Post()
        {
            HttpContent requestContent = Request.Content;
            string jsonContent = requestContent.ReadAsStringAsync().Result;

            LoginModel dat = new LoginModel();

            var dats = JsonConvert.DeserializeObject<LoginModel>(jsonContent);
            dat = dats;
            RACKNEEntities db = new RACKNEEntities();

            if (db.LOGIN_INFO.Count(s => s.USERNAME == dat.User && s.PASS == dat.Pass) == 0)
            {
                return false;
            }
            else
            {
               return true;
            }
        }