Create Route for a specific URL without changing the URL with MVC

前端 未结 3 1201
栀梦
栀梦 2021-01-19 02:57

I have a MVC Web Application that runs on www.domain.com and I need to configure a different URL binding for another domain www.domain2.com for the

3条回答
  •  灰色年华
    2021-01-19 03:29

    Agreed with the answer above.

    If you want more beautiful implementation - try action filters. Sample of action filters usage from there.

    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var controller = (SomeControllerBase) filterContext.Controller;
        filterContext.Result = controller.RedirectToAction("index", "home");
    }
    

    Sample of getting the URL inside action filter from there.

    var url = filterContext.HttpContext.Request.Url;
    

    Put the things together and have fun :)

提交回复
热议问题