public ActionResult SiteRedirect() { if (User.Identity.IsAuthenticated) { // Sign the user out of the override interface, if they were logged in. FormsAuthentication.SignOut(); } if (TempData.ContainsKey(BLOCK_MODEL_TEMPDATA_KEY)) { BlockRequestModel model = (BlockRequestModel)TempData[BLOCK_MODEL_TEMPDATA_KEY]; if (model != null) { return(View(model)); } else { // Redirect to an error page, where they can try again. return(null); } } else { // Redirect to an error page, where they can try again. return(null); } }
/// <summary> /// Overrides the web filter. /// </summary> /// <returns></returns> public ActionResult Do() { // Get the block request object from session state. BlockRequestModel model = (BlockRequestModel)Session[MvcApplication.SESSION_BLOCK_REQUEST_NAME]; // Get the User ID of the currently logged in user. model.UserId = User.Identity.Name; if (!string.IsNullOrWhiteSpace(MvcApplication.overridePayloadTemplate)) { try { StringBuilder payload = new StringBuilder(MvcApplication.overridePayloadTemplate); payload.Replace("%IP%", model.SourceIP); // Ignore certificate checking for this connection. (Self-signed certs. Note: this is global to the application.) RemoteCertificateValidationCallback previousCallback = ServicePointManager.ServerCertificateValidationCallback; ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; // Make a GET request to the firewall with the override XML payload. string url = "https://" + MvcApplication.FIREWALL_HOSTNAME + "/api/?type=user-id&key=" + MvcApplication.PAN_API_KEY + "&cmd=" + Url.Encode(payload.ToString()); WebRequest request = WebRequest.Create(url); WebResponse response = request.GetResponse(); // Reinstate certificate checking. ServicePointManager.ServerCertificateValidationCallback = previousCallback; // Add the override to the list of active overrides in the database. MSStoredProcedure upsert = new MSStoredProcedure(MvcApplication.databaseConnectionString, MvcApplication.STORED_PROCEDURE_UPSERT_OVERRIDE, MvcApplication.eventLog); upsert.AddNVarCharParameter(MvcApplication.STORED_PROCEDURE_PARAM_IP, model.SourceIP, MvcApplication.STORED_PROCEDURE_PARAM_IP_LENGTH, StoredProcedure.ParameterType.In); upsert.AddNVarCharParameter(MvcApplication.STORED_PROCEDURE_PARAM_USERNAME, model.UserId, MvcApplication.STORED_PROCEDURE_PARAM_USERNAME_LENGTH, StoredProcedure.ParameterType.In); if (upsert.ExecuteNonQuery() > 0) { // Log the override in the event log. MvcApplication.Log(new Galactic.EventLog.Event(MvcApplication.EVENT_LOG_SOURCE_NAME, DateTime.Now, Galactic.EventLog.Event.SeverityLevels.Information, MvcApplication.EVENT_LOG_CATEGORY_OVERRIDE, "User: "******" IP: " + model.SourceIP + " URL: " + model.Url)); } else { // Log an error in the event log. MvcApplication.Log(new Galactic.EventLog.Event(MvcApplication.EVENT_LOG_SOURCE_NAME, DateTime.Now, Galactic.EventLog.Event.SeverityLevels.Error, MvcApplication.EVENT_LOG_CATEGORY_OVERRIDE, "Unable to save override to database. User: "******" IP: " + model.SourceIP + " URL: " + model.Url)); } } catch (Exception e) { // Catch any exceptions here. // Redirect to an error page, where they can try again. MvcApplication.Log(new Galactic.EventLog.Event(MvcApplication.EVENT_LOG_SOURCE_NAME, DateTime.Now, Galactic.EventLog.Event.SeverityLevels.Error, MvcApplication.EVENT_LOG_CATEGORY_OVERRIDE, "Unhandled exception.\nMessage: " + e.Message + "\nInner Exception: " + e.InnerException + "\nStack Trace: " + e.StackTrace)); return(null); } } // Redirect the user to the site they initially requested. TempData[BLOCK_MODEL_TEMPDATA_KEY] = model; return(RedirectToAction("SiteRedirect")); }
public ActionResult Contact(string RoomIndexs) { if (RoomIndexs == null) { return(RedirectToAction("Error")); } string tid = hadc.GetTokenId(); HotelRoomsDetails hf = JsonConvert.DeserializeObject <HotelRoomsDetails>(RoomIndexs); HotelRoomDetail hd = JsonConvert.DeserializeObject <HotelRoomDetail>(RoomIndexs); hd.SmokingPreference = "0"; hd.BedTypeCode = null; BlockRequestModel block = new BlockRequestModel(); block.EndUserIp = ip.Replace(" ", ""); block.TokenId = tid; block.TraceId = Session["TId"].ToString(); block.GuestNationality = "IN"; block.HotelName = Request.QueryString["Hotelname"]; block.HotelCode = Request.QueryString["HotelCode"]; block.ResultIndex = Convert.ToInt32(Request.QueryString["Resultindex"]); block.IsVoucherBooking = true; block.NoOfRooms = 1; block.HotelRoomsDetails = new List <HotelRoomDetail>(); block.HotelRoomsDetails.Add(hd); string json = JsonConvert.SerializeObject(block); string Data = null; HttpClient client = new HttpClient(); client.BaseAddress = new Uri(BaseUriFormHotelSearch); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); try { var contentData = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage responseMessage = client.PostAsync("rest/BlockRoom", contentData).Result; Data = responseMessage.Content.ReadAsStringAsync().Result; //var result = JsonConvert.DeserializeObject<HotelResult>(Data); } catch (AggregateException ae) { Console.WriteLine(ae); } catch (SocketException se) { Console.WriteLine(se); } catch (WebException ex) { Console.WriteLine(ex); } ViewBag.response = Data; TempData["Bookdata"] = hf; return(View()); }