问题
does anyone know how to pass a URL as a query string parameter and then get the URl in HttpGet method as a parameter ?
回答1:
Thanks so much for all the answers. Finally I got it sorted. Please refer to my fix below:
[Route("api/[controller]")]
public class UrlController : Controller
{
[HttpGet("{*longUrl}")]
public string ShortUrl(string longUrl)
{
var test = longUrl + Request.QueryString;
return JsonConvert.SerializeObject(GetUrlToken(test));
}
回答2:
just like this?
<a href="/Home/Index?url=@HttpUtility.UrlEncode("http://stackoverflow.com")">current url with UrlEncode</a>
[HttpGet]
public ActionResult Index(string url = null)
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
return View();
}
回答3:
HttpUtility.UrlEncode should do the job for you
404 might be because the application is not in running mode
host you application and try it in local it should be working as needed
i was trying as http://localhost:11331/Home/?id=http%3A%2F%2Flocalhost%3A11331%2F
and everything is working fine even the redirection to the launch screen
or else post the complete URL you are getting so that i can help you
来源:https://stackoverflow.com/questions/30648222/how-to-pass-a-url-as-a-query-string-parameter-in-mvc