我正在研究mvc中的向导类型应用程序,它将帮助人们预约他们的预约,首页它有访问的理由,然后选择医生就像明智一样,它会去预约。我有post和get方法来维护页面之间的数据。此应用程序不维护任何用户特定的会话,而是根据医院ID维护会话(他们可以预约任何医院的医院链,没有基于用户的身份验证,基于医院ID的会话维护)。
我的会话创建方法是:
public AppointmentRequest InitAppointmentRequest(string hospitalId)
{
var objAppointment = new AppointmentRequest();
_Appointment_WorkingState = "Appointment.WorkingState" + ":" + hospitalId;
HttpContext.Current.Session[_Appointment_WorkingState] = objAppointment;
return objAppointment;
}
public AppointmentRequest GetAppointmentSession(int hospitalId)
{
_Appointment_WorkingState = "Appointment.WorkingState" + ":" + hospitalId;
if (HttpContext.Current.Session[_Appointment_WorkingState] != null)
return (AppointmentRequest)HttpContext.Current.Session[_Appointment_WorkingState];
return null;
//return RedirectToRouteResult("Index", "Appointment");
}
如果用户只打开一个网址(http://localhost:53430/?hospitalid=153),则工作正常,如果用户在同一浏览器中复制了不同医院(http://localhost:53430/?hospitalid=152)的相同网址,则无法正常工作。
如果我发布页面,我将从模型中传递出来并正常工作。如果为医院152单击一下,在同一浏览器的下一个选项卡中导航到其他医院153并返回到152并单击后退按钮,因为我无法获得医院ID是get方法。
public ActionResult Index(string hospitalid)
{
var appointment = AppointmentRequest.InitAppointmentRequest(hospitalid);
//some logics
return view("index");
}
[HttpPost]
[Route("select-appointment-reason")]
public ActionResult AppointmentReason(AppointmentRequest model, FormCollection collection)
{
var appointment = AppointmentRequest.GetAppointmentSession(model.HospitalId);
//var appointment = AppointmentRequest.GetCurrent();
}
[HttpGet]
[Route("select-appointment-reason")]
public ActionResult AppointmentReason()
{
// i need hospital id here to get the exact session.
var appointment = AppointmentRequest.GetAppointmentSession(hospitalid);
return view(appointment);
}
在get方法中,我需要在调用getappointmentsession
之前获取医院ID以获取确切的会话值。目前我没有任何隐藏字段,我知道,我只能在post方法表单集合中获取隐藏字段值。我在get方法中需要医院ID,这是我的要求或解决此问题的最佳方法。