ASP.NET Core routing prefix

后端 未结 5 1082
余生分开走
余生分开走 2021-01-17 17:45

I\'m developing an ASP.NET Core application. My application hosted with NGinx on url http://somedomain.com/MyApplication.

I need all requests routed to

5条回答
  •  一整个雨季
    2021-01-17 17:52

    Attribute routing for ASP.NET Core.In the below example shows

    [Route("MyApplication")]
    public class MyController : Controller
    {
        //You can have multiple routes on an action
        [Route("")] /MyApplication
        [Route("/test")] you have move to the /MyApplication/test 
        [HttpGet]
        public async Task Login(string returnUrl = null)
        {
            //Your Code Session
        }
    }
    

    OR you use Attribute routing with Http[Verb] attributes. To be add the path in [HttpGet("Your Path")],In the case of [HttpPost("Your Path")].

    [HttpGet("/MyApplication")]
            [AllowAnonymous]
            public async Task Login(string returnUrl = null)
            {
                // Clear the existing external cookie to ensure a clean login process
                await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
    
                ViewData["ReturnUrl"] = returnUrl;
                return View();
            }
    

提交回复
热议问题