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.

0

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

Sir, I want something permanent solution that applies if I change hostname as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.