简体   繁体   中英

How to create in ASP.Net Core specific URL

How to create route like site.net/query ?

Attention, not

site.net/?q=querystring

What I want is:

site.net/querystring

I tried something like this, but this don't work

[Route("")]
class MyController : Controller
{
  [HttpGet]
  public string Get()
  {
    return Request.QueryString.ToString();
  }

Just put that path in the routing string:

[HttpGet("/Something/[action]/{q}")]
public string Get(string q)
{
    return q;
}

When you access this link: localhost/Something/Get/mynicestring

mynicestring will be shown

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM