Asp.net mvc MVC:为每个用户生成唯一的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

我想为每个用户创建一个唯一的url,这样我就可以将该url发送到他们的电子邮件中,然后他们可以根据该url发布回复

比如说,, 假设有一个Id为guid类型的约会,并且有人(与会者)将参加某个约会。这些与会者还将拥有自己的guid类型Id

因此,要发布回复,用户将获得一个包含appointmentid和他/她的attendeeid的url,单击该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

例如,如果我只有一个参数(例如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发送到用户的电子邮件
  • 当用户单击URL时,在您的操作中,您可以从数据库中读取相应的
    任命ID的
    与会者ID

  • 我有一个名为
    Attendes
    的表,它由
    AppointmentId
    AttendeeId
    组成。我需要根据表中的值生成url。因此,您可以从数据库中创建它,并生成类似上面示例的url。通过
    分离参数。您能给出一个示例吗?假设var
    appointmentId=someguidId
    var attendeeId=someguidId
    那么如何创建url呢?
    string url=”http://localhost:14834/Appointment/Create?appointmentId=“+appointmentId+”&attendeeId=“+attendeeId
    类似的内容?感谢您在+1之前提供帮助;)