.net core routing to a razor pages area based on current domain name?
I'm currently trying to architect a application to host multiple websites from a single .net core application.
Ideally, I would like to show completely different Razor pages based on the domain name the application is being accessed from.
Ideally, I would like to have my razor pages broken down into areas, where each area is associated with a different domain name. IE www.domain1.com is the domain1 area, www.domain2.com is the domain2 area, and each area has it's own index about page etc.
So if someone accesses the application from www.domain1.com/aboutus , it would direct them to the razor pages located in the Area/Domain1/Pages/AboutUs section of my application.
Similarly if my application were to receive a request to www.domain2.com/aboutus, they would see the about us page located under Area/Domain2/Pages/Aboutus.
I've been searching for hours, and I can't figure out how you accomplish this using razor pages area feature. The only information I can find is how to accomplish this using areas with vanilla MVC.
This was a pretty good example.
Different domain in the same app ASP.NET Core 2.0
I can't figure out how to accomplish the same type of thing using razor pages.
routing routes .net-core asp.net-mvc-areas razor-pages
add a comment |
I'm currently trying to architect a application to host multiple websites from a single .net core application.
Ideally, I would like to show completely different Razor pages based on the domain name the application is being accessed from.
Ideally, I would like to have my razor pages broken down into areas, where each area is associated with a different domain name. IE www.domain1.com is the domain1 area, www.domain2.com is the domain2 area, and each area has it's own index about page etc.
So if someone accesses the application from www.domain1.com/aboutus , it would direct them to the razor pages located in the Area/Domain1/Pages/AboutUs section of my application.
Similarly if my application were to receive a request to www.domain2.com/aboutus, they would see the about us page located under Area/Domain2/Pages/Aboutus.
I've been searching for hours, and I can't figure out how you accomplish this using razor pages area feature. The only information I can find is how to accomplish this using areas with vanilla MVC.
This was a pretty good example.
Different domain in the same app ASP.NET Core 2.0
I can't figure out how to accomplish the same type of thing using razor pages.
routing routes .net-core asp.net-mvc-areas razor-pages
By area do you mean asp.net mvc area or just a subfolder? did you get chance to check aspnetboilerplate.com or cloudscribe.com. Instead of starting from scratch, you can learn and adapt to what they already resolved.
– Prashant Lakhlani
Sep 28 '18 at 10:42
MVC areas, were added to razor pages in 2.1. mikesdotnetting.com/article/324/areas-in-razor-pages However, I cannot figure out how to use the domain name to constrain the route to specific areas.
– IMelancon
Sep 28 '18 at 13:13
add a comment |
I'm currently trying to architect a application to host multiple websites from a single .net core application.
Ideally, I would like to show completely different Razor pages based on the domain name the application is being accessed from.
Ideally, I would like to have my razor pages broken down into areas, where each area is associated with a different domain name. IE www.domain1.com is the domain1 area, www.domain2.com is the domain2 area, and each area has it's own index about page etc.
So if someone accesses the application from www.domain1.com/aboutus , it would direct them to the razor pages located in the Area/Domain1/Pages/AboutUs section of my application.
Similarly if my application were to receive a request to www.domain2.com/aboutus, they would see the about us page located under Area/Domain2/Pages/Aboutus.
I've been searching for hours, and I can't figure out how you accomplish this using razor pages area feature. The only information I can find is how to accomplish this using areas with vanilla MVC.
This was a pretty good example.
Different domain in the same app ASP.NET Core 2.0
I can't figure out how to accomplish the same type of thing using razor pages.
routing routes .net-core asp.net-mvc-areas razor-pages
I'm currently trying to architect a application to host multiple websites from a single .net core application.
Ideally, I would like to show completely different Razor pages based on the domain name the application is being accessed from.
Ideally, I would like to have my razor pages broken down into areas, where each area is associated with a different domain name. IE www.domain1.com is the domain1 area, www.domain2.com is the domain2 area, and each area has it's own index about page etc.
So if someone accesses the application from www.domain1.com/aboutus , it would direct them to the razor pages located in the Area/Domain1/Pages/AboutUs section of my application.
Similarly if my application were to receive a request to www.domain2.com/aboutus, they would see the about us page located under Area/Domain2/Pages/Aboutus.
I've been searching for hours, and I can't figure out how you accomplish this using razor pages area feature. The only information I can find is how to accomplish this using areas with vanilla MVC.
This was a pretty good example.
Different domain in the same app ASP.NET Core 2.0
I can't figure out how to accomplish the same type of thing using razor pages.
routing routes .net-core asp.net-mvc-areas razor-pages
routing routes .net-core asp.net-mvc-areas razor-pages
asked Sep 28 '18 at 1:26
IMelanconIMelancon
62
62
By area do you mean asp.net mvc area or just a subfolder? did you get chance to check aspnetboilerplate.com or cloudscribe.com. Instead of starting from scratch, you can learn and adapt to what they already resolved.
– Prashant Lakhlani
Sep 28 '18 at 10:42
MVC areas, were added to razor pages in 2.1. mikesdotnetting.com/article/324/areas-in-razor-pages However, I cannot figure out how to use the domain name to constrain the route to specific areas.
– IMelancon
Sep 28 '18 at 13:13
add a comment |
By area do you mean asp.net mvc area or just a subfolder? did you get chance to check aspnetboilerplate.com or cloudscribe.com. Instead of starting from scratch, you can learn and adapt to what they already resolved.
– Prashant Lakhlani
Sep 28 '18 at 10:42
MVC areas, were added to razor pages in 2.1. mikesdotnetting.com/article/324/areas-in-razor-pages However, I cannot figure out how to use the domain name to constrain the route to specific areas.
– IMelancon
Sep 28 '18 at 13:13
By area do you mean asp.net mvc area or just a subfolder? did you get chance to check aspnetboilerplate.com or cloudscribe.com. Instead of starting from scratch, you can learn and adapt to what they already resolved.
– Prashant Lakhlani
Sep 28 '18 at 10:42
By area do you mean asp.net mvc area or just a subfolder? did you get chance to check aspnetboilerplate.com or cloudscribe.com. Instead of starting from scratch, you can learn and adapt to what they already resolved.
– Prashant Lakhlani
Sep 28 '18 at 10:42
MVC areas, were added to razor pages in 2.1. mikesdotnetting.com/article/324/areas-in-razor-pages However, I cannot figure out how to use the domain name to constrain the route to specific areas.
– IMelancon
Sep 28 '18 at 13:13
MVC areas, were added to razor pages in 2.1. mikesdotnetting.com/article/324/areas-in-razor-pages However, I cannot figure out how to use the domain name to constrain the route to specific areas.
– IMelancon
Sep 28 '18 at 13:13
add a comment |
1 Answer
1
active
oldest
votes
I'm not sure how scalable using Areas for this is, but you can use middleware to identify the domain and serve content from an area based on that, something like this, where "bloggs" is the name of an area for the bloggs.com domain:
public class AreaRoutingMiddleware
{
private readonly RequestDelegate _next;
public AreaRoutingMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
if(context.Request.Host.ToString() == "bloggs.com")
{
context.Request.Path = "/bloggs" + context.Request.Path;
}
await _next.Invoke(context);
}
}
You may also need to add checks for file types, unless all files (css, js, favicon etc) also reside in the respective area.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52547068%2fnet-core-routing-to-a-razor-pages-area-based-on-current-domain-name%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm not sure how scalable using Areas for this is, but you can use middleware to identify the domain and serve content from an area based on that, something like this, where "bloggs" is the name of an area for the bloggs.com domain:
public class AreaRoutingMiddleware
{
private readonly RequestDelegate _next;
public AreaRoutingMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
if(context.Request.Host.ToString() == "bloggs.com")
{
context.Request.Path = "/bloggs" + context.Request.Path;
}
await _next.Invoke(context);
}
}
You may also need to add checks for file types, unless all files (css, js, favicon etc) also reside in the respective area.
add a comment |
I'm not sure how scalable using Areas for this is, but you can use middleware to identify the domain and serve content from an area based on that, something like this, where "bloggs" is the name of an area for the bloggs.com domain:
public class AreaRoutingMiddleware
{
private readonly RequestDelegate _next;
public AreaRoutingMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
if(context.Request.Host.ToString() == "bloggs.com")
{
context.Request.Path = "/bloggs" + context.Request.Path;
}
await _next.Invoke(context);
}
}
You may also need to add checks for file types, unless all files (css, js, favicon etc) also reside in the respective area.
add a comment |
I'm not sure how scalable using Areas for this is, but you can use middleware to identify the domain and serve content from an area based on that, something like this, where "bloggs" is the name of an area for the bloggs.com domain:
public class AreaRoutingMiddleware
{
private readonly RequestDelegate _next;
public AreaRoutingMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
if(context.Request.Host.ToString() == "bloggs.com")
{
context.Request.Path = "/bloggs" + context.Request.Path;
}
await _next.Invoke(context);
}
}
You may also need to add checks for file types, unless all files (css, js, favicon etc) also reside in the respective area.
I'm not sure how scalable using Areas for this is, but you can use middleware to identify the domain and serve content from an area based on that, something like this, where "bloggs" is the name of an area for the bloggs.com domain:
public class AreaRoutingMiddleware
{
private readonly RequestDelegate _next;
public AreaRoutingMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
if(context.Request.Host.ToString() == "bloggs.com")
{
context.Request.Path = "/bloggs" + context.Request.Path;
}
await _next.Invoke(context);
}
}
You may also need to add checks for file types, unless all files (css, js, favicon etc) also reside in the respective area.
answered Sep 30 '18 at 8:31
Mike BrindMike Brind
17.5k54070
17.5k54070
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52547068%2fnet-core-routing-to-a-razor-pages-area-based-on-current-domain-name%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
By area do you mean asp.net mvc area or just a subfolder? did you get chance to check aspnetboilerplate.com or cloudscribe.com. Instead of starting from scratch, you can learn and adapt to what they already resolved.
– Prashant Lakhlani
Sep 28 '18 at 10:42
MVC areas, were added to razor pages in 2.1. mikesdotnetting.com/article/324/areas-in-razor-pages However, I cannot figure out how to use the domain name to constrain the route to specific areas.
– IMelancon
Sep 28 '18 at 13:13