0

I am trying to send activation mail to the currently registered user.In mail body,I need to send a link like http://example.com/account/activation?username=d&email=g.Now, for debugging on local machine, I manually write it as localhost:30995/account/activation?username=d&email=g. But, when my port number changes, I need to rewrite it. I tried another question on this website,but, compiler gives error like url.action doesnot exist.

Please give me fresh solution as I am confused with that solution.

Community
  • 1
  • 1
Mukesh Sharma
  • 8,914
  • 8
  • 38
  • 55

2 Answers2

3

Use a Url.Action overload that takes a protocol parameter to generate your URLs:

Url.Action("Activation", "Account", new { username = "d", email = "g" }, "http")

This generates an absolute URL rather than a relative one. The protocol can be either "http" or "https". So this will return http://localhost:XXXXX/account/activation?username=d&email=g on your local machine, and http://example.com/account/activation?username=d&email=g on production.

In short, this will stick whatever domain you're hosting your app on in front of your URL; you can then change your hostname/port number/domain name as many times as you want. Your links will always point to the host they originated from. That should solve the problem you're facing.

Daniel Liuzzi
  • 16,807
  • 8
  • 52
  • 57
0

Try using IIS / IIS-Express instead of Casinni web server that comes with visual studio.

You could add bindings to have the right URL (with host entries of course).

This will avoid the port numbers in your links.

Srikanth Venugopalan
  • 9,011
  • 3
  • 36
  • 76