Reputation: 41
I have a website (http://jsoncore.net) that I am using to learn .NET Core 2 and I want to remove the shared hosting folder name from the URL that is added to links and sources. For example I add an Html.ActionLink like this:
@Html.ActionLink(page.NavTitle, page.Slug, "Home")
and the system writes it to this:
<a href="/jsoncore/blog">Blog</a>
I want to remove the "/jsoncore" from the link URL so that it should look like this:
<a href="/blog">Blog</a>
Here are the routes defined in Startup.cs:
app.UseMvc(routes =>
{
routes.MapRoute(
"AdminController",
"Admin/{action}",
new { controller = "Admin", action = "Index"}
);
routes.MapRoute(
"BlogController-BlogHome",
"Blog/",
new { controller = "Blog", action = "Index" }
);
routes.MapRoute(
"BlogController-Post",
"Post/{id}",
new { controller = "Blog", action = "Post", id = "" }
);
routes.MapRoute(
"BlogController-Post-Tag",
"Blog/Tag/{id}",
new { controller = "Blog", action = "Tag", id = "" }
);
routes.MapRoute(
"BlogController-Post-Category",
"Blog/Category/{id}",
new { controller = "Blog", action = "Category", id = "" }
);
routes.MapRoute(
"HomeController",
"{action}/{id}",
new { controller = "Home", action = "Index", id = "id?" }
);
routes.MapRoute("AccountController", "Login", new { controller = "Account", action = "Login"});
routes.MapRoute("page", "{id}", new { controller = "Home", action = "Page", url = "" });
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
Upvotes: 1
Views: 514
Reputation: 239440
If the site is hosted in a virtual directory /jsoncore/
there's no way to remove that from the URL, as it's actually part of the URL, i.e. you need that to get to the right place. Otherwise, the requests would hit the site hosted at just http://jsoncore.net
, which isn't this application. It's called a Universal Resource Locator for a reason. Only the correct URL will work, which includes the /jsoncore/
part, apparently.
Some shared hosting lets you bind to a domain or subdomain (although there'd probably be an upcharge for that). If that's available, that would be your best bet. Then, you can effectively host your site at the root of that domain/subdomain, without needing a path prefix.
Upvotes: 1