I am working on a multi-tenant project using Asp.Net MVC. I have created a custom route:
routes.Add("subdomain", new SubdomainRoute(
domain: "{tenant}.example.com",
url: "Admin/{controller}/{action}",
defaults: new { tenant = "", controller = "Tenant", action = "Index", area = "Admin" }
));
I want to know how can i redirect user to this route. Means when user get registered i want to redirect him to subdomain john.example.com/Admin/Dashboard/Index . I tried:
return RedirectToRoute(new { tenant = "john" }); //this not work
return RedirectToAction("Index", "Dashboard", new { tenant = model.Username, area = "Admin" }); //this result localhost:1025/Admin/Dashboard?tenant=john
BTW i have all required changes in host file.
You can use below way to redirect user from your Tenant controller.
public ActionResult Index()
{
return Redirect("http://john.example.com/Admin/Tenant/Index");
}
Try RedirectToAction method. Check this link:
http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.redirecttoaction(v=vs.118).aspx
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.