Question

I want to create unique url to each user so that I can send that url to their email and following that url they can post their reply.

For example, Let us suppose there is an appointment with Id of type guid, and there are peoples(attendee) who will attend certain appointment. These attendees will also have their own Id of type guid.

So to post a reply a user would get a url that would contain appointmentid and his/her attendeeid, and upon clicking that url, if I have a controller for example like below it would forward user to this controller

   public class ResponseController : Controller
    {

        [HttpGet]
        public AttendeeResponse(Guid appointmentId, Guid attendeeId)
        {
           return View();
        }
   }

How should I generate this kind of url?

if i just have one parameter(appointmentid for example) for example

   public class AppointmentController : Controller
    {

        [HttpGet]
        public Create(Guid appointmentId)
        {
           return View();
        }
   }

this is how the url would look like that would forward me to above method in controller

http://localhost:14834/Appointment/Create?appointmentId=e2fd8b29-2769-406a-b03d-203f9675edde

But if I have to create unique url by myself with two parameters, how would I do that?

Was it helpful?

Solution

To add more parameters in the url, you could separate parameters on the url using the & char, for sample:

http://localhost:14834/Appointment/Create?appointmentId=e2fd8b29-2769-406a-b03d-203f9675edde&attendeeId=e2fd8b29-2769-406a-b03d-203f9675edde

And asp.net mvc will bind it for you on the Guid objects of your action.

A sample of code:

public static string CreateUrl(Guid appointmentId, Guid attendeeId)
{
    return string.Format("http://yourdomain.com/Response/AttendeeResponse?appointmentId={0}&attendeeId={1}", appointmentId.ToString(), attendeeId.ToString());
}

And since you have the guids objects, you could just use this method, for sample:

string url = CreateUrl(appointmentGuid, attendeeguid);

Another solution

Anyway, do you have any place to store the appointments right? I mean, a table in a database for sample.

Maybe you could do these steps:

  1. you could generate a Guid for appointmentId and another Guid for attendeeId.
  2. Store it on database for future access.
  3. Send the the url with the appointmentId to user's email.
  4. When the user click on the URL, on your action you could read from database what is the attendeeId for the respective appointmentId.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top