Asp.net mvc MVC:为每个用户生成唯一的url
我想为每个用户创建一个唯一的url,这样我就可以将该url发送到他们的电子邮件中,然后他们可以根据该url发布回复 比如说,, 假设有一个Id为guid类型的约会,并且有人(与会者)将参加某个约会。这些与会者还将拥有自己的guid类型Id 因此,要发布回复,用户将获得一个包含appointmentid和他/她的attendeeid的url,单击该url后,如果我有一个控制器(例如下面的控制器),它会将用户转发到此控制器Asp.net mvc MVC:为每个用户生成唯一的url,asp.net-mvc,routing,asp.net-mvc-routing,asp.net-mvc-5,Asp.net Mvc,Routing,Asp.net Mvc Routing,Asp.net Mvc 5,我想为每个用户创建一个唯一的url,这样我就可以将该url发送到他们的电子邮件中,然后他们可以根据该url发布回复 比如说,, 假设有一个Id为guid类型的约会,并且有人(与会者)将参加某个约会。这些与会者还将拥有自己的guid类型Id 因此,要发布回复,用户将获得一个包含appointmentid和他/她的attendeeid的url,单击该url后,如果我有一个控制器(例如下面的控制器),它会将用户转发到此控制器 public class ResponseController : C
public class ResponseController : Controller
{
[HttpGet]
public AttendeeResponse(Guid appointmentId, Guid attendeeId)
{
return View();
}
}
http://localhost:14834/Appointment/Create?appointmentId=e2fd8b29-2769-406a-b03d-203f9675edde
我应该如何生成这种url
例如,如果我只有一个参数(例如appointmentid)
public class AppointmentController : Controller
{
[HttpGet]
public Create(Guid appointmentId)
{
return View();
}
}
这就是url的样子,它会将我转发到控制器中的上述方法
public class ResponseController : Controller
{
[HttpGet]
public AttendeeResponse(Guid appointmentId, Guid attendeeId)
{
return View();
}
}
http://localhost:14834/Appointment/Create?appointmentId=e2fd8b29-2769-406a-b03d-203f9675edde
但是如果我必须用两个参数自己创建一个唯一的url,我该怎么做呢?要在url中添加更多参数,您可以使用
&
字符在url
上分离参数,例如:
http://localhost:14834/Appointment/Create?appointmentId=e2fd8b29-2769-406a-b03d-203f9675edde&attendeeId=e2fd8b29-2769-406a-b03d-203f9675edde
string url = CreateUrl(appointmentGuid, attendeeguid);
asp.net mvc将在您操作的Guid
对象上为您绑定它
代码示例:
public static string CreateUrl(Guid appointmentId, Guid attendeeId)
{
return string.Format("http://yourdomain.com/Response/AttendeeResponse?appointmentId={0}&attendeeId={1}", appointmentId.ToString(), attendeeId.ToString());
}
因为您有guids对象,所以可以使用此方法,例如:
http://localhost:14834/Appointment/Create?appointmentId=e2fd8b29-2769-406a-b03d-203f9675edde&attendeeId=e2fd8b29-2769-406a-b03d-203f9675edde
string url = CreateUrl(appointmentGuid, attendeeguid);
另一个解决方案
不管怎么说,你有地方存放预约吗?我的意思是,数据库中的一个表用于示例
也许您可以执行以下步骤:
appointmentId
生成Guid,并为attendeeId
生成另一个Guid李>
appointmentId
的url发送到用户的电子邮件任命ID的与会者ID
我有一个名为
Attendes
的表,它由AppointmentId
和AttendeeId
组成。我需要根据表中的值生成url。因此,您可以从数据库中创建它,并生成类似上面示例的url。通过和分离参数。您能给出一个示例吗?假设varappointmentId=someguidId
和var attendeeId=someguidId
那么如何创建url呢?string url=”http://localhost:14834/Appointment/Create?appointmentId=“+appointmentId+”&attendeeId=“+attendeeId
类似的内容?感谢您在+1之前提供帮助;)