Hi,
I have to create a BLOG section in my website. If my site is www.abc.com, then I have to create different blogs like google blogger service.
http://author1.abc.com or http://www.author1.abc.com
http://author2.abc.com or http://www.author2.abc.com
I have the ability to create unlimited sub domains but I am not able to understand how above blog URL will work. These will be virtual sub domains or will I have to create actual sub domains.
Is it possible via Url rewriting? If yes, how?
If I use Url rewriting, browser will redirect the above URL to page for which I have craeted the URL rewriting rule. I dont want to change the URL in browser.
Now every subdomain of abc.com will hit your application. If you are using ASP.NET WebForms, you can create a custom BasePage. Then in OnLoad event you can check what subdomain you get and do your logic...
Please "Mark As Answer" if the post helped you.
mitja.gti | www.mitjagti.com
1. Login into yur host panel. You will see a link ‘Subdomains’.
2. Creating a subdomain is easy with your graphical user interface.
that should do it.
anujrathi
Hi,
I have to create a BLOG section in my website. If my site is www.abc.com, then I have to create different blogs like google blogger service.
http://author1.abc.com or http://www.author1.abc.com
http://author2.abc.com or http://www.author2.abc.com
I have the ability to create unlimited sub domains but I am not able to understand how above blog URL will work. These will be virtual sub domains or will I have to create actual sub domains.
Is it possible via Url rewriting? If yes, how?
If I use Url rewriting, browser will redirect the above URL to page for which I have craeted the URL rewriting rule. I dont want to change the URL in browser.
I have already created a WildCard entry for my subdomains. But by default, all subdomains are pointing to web site root. Means if I have Default.aspx as the landing page, then the landing page of all sub domains is also Default.aspx. I am just explaning
what I want:
Is there any way by which I can set the target page of sub domains. suppose I have two pages. one is website landing page (default.aspx or index.aspx) & other one is myblog.aspx. Now I want that the landing page of all subdomains (or specific) should be
myblog.aspx. Because if the landing page of sub domains is not myblog.aspx then I will have to redirect the request from Default.aspx to myblog.aspx & this process will change the Url in the browser.
Is it possible by Url Rewriting or Routing? OR is there any other way to do this?
As I have seen your website, you have a blog section. Is your site's landing page & landing page of blog hitting the same page or they are hitting different locations.
You can configure the default landing page for the application in your IIS, web.config or visual studio. In this case your myblog.aspx will become the default landing page.
In IIS click on your application and then in right pane click Default Document icon. On the right side (under Actions) click add and insert your page (myblog.aspx). Also make sure it's the first one on top (IIS will direct users to the first
one from the top - if it is available). If you click on it in the middle pane, arrow to move or delete will appear.
In Visual Studio right click on myblog.aspx and select set as start page. You can also right click on your application in solution explorer and select properties. Then select Web tab and in start action select Specific Page, enter/navigate to myblog.aspx.
If you create a basePage as advised in my previous post then you can do your logic there (if you don't want to set default landing page myblog.aspx for the whole application). Every page that will inherit from your basePage will trigger events defined in it (you can find more about ASP.NET Page Life Cycle here).
I'd suggest you override OnPreInit event and query database for all the users (you can also use caching). Then use Request.Url to get the domain and check if the user with that domain exists. If it does you don't have to do anything or you can redirect them to myblog.aspx page if you haven't set it as the applications default landing page. If the page does not exsist, then return 404.
Example
public class BasePage : Page
{
protected override void OnPreInit(EventArgs e)
{
string subDomain = GetSubDomain(Request.Url);
if (subDomain != null)
{
// Query DB - use caching too
string[] users = { "author1", "author2", "author3" };
if (users.Contains(subDomain))
Response.RedirectPermanent("~/myblog.aspx");
else
throw new HttpException(404, "No blog exsists!");
}
base.OnInit(e);
}
private static string GetSubDomain(Uri url)
{
if (url.HostNameType == UriHostNameType.Dns)
{
string host = url.Host;
if (host.Split('.').Length > 2)
{
int lastIndex = host.LastIndexOf(".");
int index = host.LastIndexOf(".", lastIndex - 1);
return host.Substring(0, index);
}
}
return null;
}
}
Your page by default inherits from System.Web.UI.Page
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
Now you need to inherit from your custom BasePage
public partial class _Default : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
Please "Mark As Answer" if the post helped you.
mitja.gti | www.mitjagti.com
I am 100% agree with you regarding "Default Document" concept & top level base page class. Your explaination is very good.
I think I was not able to explain waht I want to ask exactly.
my conserned is: if I request "www.abc. com" then our "Default.aspx" will be accessed (because this default landing page or we can say this is default document for this application). This is true & I have no doubt.
Now I request "http://xyz.abc.com", now I don't want to HIT "default docuement" of site (& I can't change the default document from default.aspx to myblog.aspx).
As per your explanation, we will perform a permanent redirect (Response.RedirectPermanent) which will change the URL from "http://xyz.abc.com" to "http://www.abc.com/myblog.aspx" in the browser.
I don't want to change the URL in front end (user's browser) that's why I was asking that Is there any way to HIT "myblog.aspx" directly if request "http://xyz.abc.com".
This is just like that If I request "contactus.aspx" then my request will hit contactus.aspx page not default.aspx page.
anujrathi
Member
265 Points
124 Posts
How to create Google blogger type Sub Domain URL for blog
Aug 12, 2012 07:43 PM|LINK
Hi,
I have to create a BLOG section in my website. If my site is www.abc.com, then I have to create different blogs like google blogger service.
http://author1.abc.com or http://www.author1.abc.com
http://author2.abc.com or http://www.author2.abc.com
I have the ability to create unlimited sub domains but I am not able to understand how above blog URL will work. These will be virtual sub domains or will I have to create actual sub domains.
Is it possible via Url rewriting? If yes, how?
If I use Url rewriting, browser will redirect the above URL to page for which I have craeted the URL rewriting rule. I dont want to change the URL in browser.
Any one has any suggestion?
mitja.GTI
Star
11157 Points
2094 Posts
Re: How to create Google blogger type Sub Domain URL for blog
Aug 14, 2012 02:03 AM|LINK
You should add *.abc.com (WildCard) to your DNS records. This can usually be done from control panel (hosting enviroment).
Configuring bindings in your IIS will require a little trick -> Wildcard Host Header Binding And Subdomains with IIS7.
Now every subdomain of abc.com will hit your application. If you are using ASP.NET WebForms, you can create a custom BasePage. Then in OnLoad event you can check what subdomain you get and do your logic...
mitja.gti | www.mitjagti.com
graciax8
Participant
765 Points
212 Posts
Re: How to create Google blogger type Sub Domain URL for blog
Aug 14, 2012 03:13 AM|LINK
if you are hosting your site,
1. Login into yur host panel. You will see a link ‘Subdomains’.
2. Creating a subdomain is easy with your graphical user interface.
that should do it.
mycodepad.blogspot.com || TUMBLR
anujrathi
Member
265 Points
124 Posts
Re: How to create Google blogger type Sub Domain URL for blog
Aug 14, 2012 08:38 AM|LINK
Hi Mavser,
I have already created a WildCard entry for my subdomains. But by default, all subdomains are pointing to web site root. Means if I have Default.aspx as the landing page, then the landing page of all sub domains is also Default.aspx. I am just explaning what I want:
Is there any way by which I can set the target page of sub domains. suppose I have two pages. one is website landing page (default.aspx or index.aspx) & other one is myblog.aspx. Now I want that the landing page of all subdomains (or specific) should be myblog.aspx. Because if the landing page of sub domains is not myblog.aspx then I will have to redirect the request from Default.aspx to myblog.aspx & this process will change the Url in the browser.
Is it possible by Url Rewriting or Routing? OR is there any other way to do this?
As I have seen your website, you have a blog section. Is your site's landing page & landing page of blog hitting the same page or they are hitting different locations.
mitja.GTI
Star
11157 Points
2094 Posts
Re: How to create Google blogger type Sub Domain URL for blog
Aug 14, 2012 11:55 AM|LINK
You can configure the default landing page for the application in your IIS, web.config or visual studio. In this case your myblog.aspx will become the default landing page.
In IIS click on your application and then in right pane click Default Document icon. On the right side (under Actions) click add and insert your page (myblog.aspx). Also make sure it's the first one on top (IIS will direct users to the first one from the top - if it is available). If you click on it in the middle pane, arrow to move or delete will appear.
In web.config
<configuration> <system.webServer> <defaultDocument> <files> <add value="myblog.aspx" /> </files> </defaultDocument> </system.webServer> </configuration>In Visual Studio right click on myblog.aspx and select set as start page. You can also right click on your application in solution explorer and select properties. Then select Web tab and in start action select Specific Page, enter/navigate to myblog.aspx.
If you create a basePage as advised in my previous post then you can do your logic there (if you don't want to set default landing page myblog.aspx for the whole application). Every page that will inherit from your basePage will trigger events defined in it (you can find more about ASP.NET Page Life Cycle here).
I'd suggest you override OnPreInit event and query database for all the users (you can also use caching). Then use Request.Url to get the domain and check if the user with that domain exists. If it does you don't have to do anything or you can redirect them to myblog.aspx page if you haven't set it as the applications default landing page. If the page does not exsist, then return 404.
Example
public class BasePage : Page { protected override void OnPreInit(EventArgs e) { string subDomain = GetSubDomain(Request.Url); if (subDomain != null) { // Query DB - use caching too string[] users = { "author1", "author2", "author3" }; if (users.Contains(subDomain)) Response.RedirectPermanent("~/myblog.aspx"); else throw new HttpException(404, "No blog exsists!"); } base.OnInit(e); } private static string GetSubDomain(Uri url) { if (url.HostNameType == UriHostNameType.Dns) { string host = url.Host; if (host.Split('.').Length > 2) { int lastIndex = host.LastIndexOf("."); int index = host.LastIndexOf(".", lastIndex - 1); return host.Substring(0, index); } } return null; } }Your page by default inherits from System.Web.UI.Page
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }Now you need to inherit from your custom BasePage
public partial class _Default : BasePage { protected void Page_Load(object sender, EventArgs e) { } }mitja.gti | www.mitjagti.com
anujrathi
Member
265 Points
124 Posts
Re: How to create Google blogger type Sub Domain URL for blog
Aug 15, 2012 04:30 AM|LINK
I am 100% agree with you regarding "Default Document" concept & top level base page class. Your explaination is very good.
I think I was not able to explain waht I want to ask exactly.
my conserned is: if I request "www.abc. com" then our "Default.aspx" will be accessed (because this default landing page or we can say this is default document for this application). This is true & I have no doubt.
Now I request "http://xyz.abc.com", now I don't want to HIT "default docuement" of site (& I can't change the default document from default.aspx to myblog.aspx).
As per your explanation, we will perform a permanent redirect (Response.RedirectPermanent) which will change the URL from "http://xyz.abc.com" to "http://www.abc.com/myblog.aspx" in the browser.
I don't want to change the URL in front end (user's browser) that's why I was asking that Is there any way to HIT "myblog.aspx" directly if request "http://xyz.abc.com".
This is just like that If I request "contactus.aspx" then my request will hit contactus.aspx page not default.aspx page.
Are you understanding what I want to ask?
mitja.GTI
Star
11157 Points
2094 Posts
Re: How to create Google blogger type Sub Domain URL for blog
Aug 15, 2012 11:22 AM|LINK
I understand your situation and It should NOT change the domain if you redirect with relative path.
Response.RedirectPermanent("~/myblog.aspx");mitja.gti | www.mitjagti.com