Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何防止编辑url地址?_C#_Asp.net_Asp.net Mvc 4_Url_Fullcalendar - Fatal编程技术网

C# 如何防止编辑url地址?

C# 如何防止编辑url地址?,c#,asp.net,asp.net-mvc-4,url,fullcalendar,C#,Asp.net,Asp.net Mvc 4,Url,Fullcalendar,我是初学者程序员,我需要一些信息。如何防止通过浏览器栏编辑参数?。看看代码。在我的控制器里,我有下面的方法 [HttpGet] public ActionResult WypelnijFormularz(int doctor, string date, string hour, string minute) { RegisterVisitModel model = new RegisterVisitModel(); model.doctor = DoctorRepository.

我是初学者程序员,我需要一些信息。如何防止通过浏览器栏编辑参数?。看看代码。在我的控制器里,我有下面的方法

[HttpGet]
public ActionResult WypelnijFormularz(int doctor, string date, string hour, string minute)
{
    RegisterVisitModel model = new RegisterVisitModel();
    model.doctor = DoctorRepository.GetDoctorByID(doctor);
    model.dateVisit = DateTime.ParseExact(date+" "+hour+":"+minute+":00", "yyyy-MM-dd HH:mm:ss", null);

    return View(model);
}
参数从此处发送:

button.url = "/Dentist/WypelnijFormularz?doctor=" + doctor + "&date=" + button.start.Date.ToString("d") + "&hour=" + button.start.ToString("HH") + "&minute=" + button.start.ToString("mm");
上面的代码是具有Fullcalendar的许多属性之一。是的,我使用完整日历插件来显示一周中的事件!(这是一个日历小时!)。选择自由项后,我们将使用上述方法。问题的核心是,我们可以在浏览器中更改日期,然后我们可以预订现有的约会。我怎样才能防止这种情况发生

我找到了一个我们无法做到的网站-> 当您更改日期时,我们知道此页面不存在。我怎么能得到这个


你好

您不能指示浏览器或任何其他可用于发送请求的工具来验证url

您需要做的是自己验证进入action方法的所有输入。您可以使用来验证传入的请求,也可以自己实现验证


你不应该相信用户输入的内容。

正如其他人所建议的,你应该这样做:

[HttpGet]
public ActionResult WypelnijFormularz(int doctor, string date, string hour, string minute)
{
     RegisterVisitModel model = new RegisterVisitModel();
     model.doctor = DoctorRepository.GetDoctorByID(doctor);
     model.dateVisit = DateTime.ParseExact(date+" "+hour+":"+minute+":00", "yyyy-MM-dd HH:mm:ss", null);

     //Check if an appointment exists on that day
     if(DoctorRepository.IsAppointmentExist(model.dateVisit))
     {
           //Redirect to error page
           return RedirectToAction("Index", "Error");
     }

     return View(model);
}

服务器端的数据验证不起作用吗?我的建议是要么使用另一种方法来指定日期ie表单字段,要么将设计更改为不太依赖日期。不幸的是,查询字符串很难验证,但您可以在模型本身上实现自定义逻辑,以确保现有约会不会被预订。我无法更改我的设计,因为我使用的是Fullcalendar events,它模拟了带有可用小时预订的按钮。每个事件都有url属性。您是说这些属性用于方法吗?[AcceptVerbs(HttpVerbs.Post)],ValidateAntiForgeryToken]请检查Vsevolod提供给您的链接。这些属性用于装饰视图模型的成员,并将在回发时进行验证。在操作中,检查ModelState.IsValid以确保在继续之前一切正常。也只是进一步重申他的观点。。。永远不要相信客户在你网站上发布的内容,这是黑客攻击的第一点occur@rejencina请参阅PaulCarroll的评论,我强烈建议您阅读asp.net网站上的一些教程