electronics routes to {product}, some-electronic-product routes to {name}, 10 routes to {id} of this product and 2 routes to {page}.
Now I want to create city wise subdomain and its URL accordingly. For Ex. If I have 2 products, one in abc city and other in XYZ city. When all the products are loaded on www.example.com/elctronics/, action links for each product should be generated with
its respective sudomain which will be city name for that product.
Accordingly for above two products, action links should be generated as follows:
there are different options for this but global.asax is the file you need to edit
this is the default
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new {controller = "Home", action = "Welcome", id = UrlParameter.Optional} // Parameter defaults
);
for your example i would use 1 controller and 1 action let's just say we go with the Home controller and the welcome action
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{name}-{id}/{page}", // URL with parameters
new {controller = "Home", action = "Welcome", id = UrlParameter.Optional, page = UrlParameter.Optional, name = UrlParameter.Optional, category = UrlParameter.Optional } // Parameter defaults
);
in your homecontroller make your method like
public ActionResult Welcome(string name = "", int id = 0, int page = 0)
{
if (string.isnullorempty(name) && id == 0 && page == 0)
{
return redirecttoaction("index");
}
else {
get your product etc....
return view();
}
}
i'm not a 100% sure about this but i think this might just work out
Thanks for your help. But unfortunitely still I couldn't make it. I will explanin my issue lil more with an example. If you visit http://www.quikr.com/Air-Conditioners-Coolers/y249
here you will see a long list of ads.
Action links for these ads are generated based on city as its subdomain.
Like http://pune.quikr.com/Supreme-Gold-Mini-Air-Cooler-W0QQAdIdZ92919271
On a page I want to list all the products from different cities. Actionlink for each product should be generated with respective city as subdomain in the URL.
Example:
On Home Page>
Product List:
1) Product one (from Mumbai) action link to generate> www.mumbai.example.com/electronics/product-one-10/
2) Product two (from delhi) action link to generate> www.delhi.example.com/electronics/product-two-11/
as soon as destination page is loaded get ur url(using ajax) break it and put the parts in viewbag and then search the database according ly in either view or JQuery it self.
Razin Memon
Software Engineer in R&D at Insigno Quipment Technologies (India) Pvt Ltd
sureshdrim
Member
2 Points
24 Posts
subdomain routing based on location parameter in MVC3
Sep 13, 2012 09:15 AM|LINK
Hi friends,
I am little puzzled, how to create subdomain based routing in MVC 3. Let me explain it with an example.
Let's say we have following route:
<add url="{product}/{name}-{id}/{page}" controller="Product" action="Detail">
which cretes URL like:
www.example.com/elctronics/some-electronic-product-10/2
where,
electronics routes to {product}, some-electronic-product routes to {name}, 10 routes to {id} of this product and 2 routes to {page}.
Now I want to create city wise subdomain and its URL accordingly. For Ex. If I have 2 products, one in abc city and other in XYZ city. When all the products are loaded on www.example.com/elctronics/, action links for each product should be generated with its respective sudomain which will be city name for that product.
Accordingly for above two products, action links should be generated as follows:
www.abc.example.com/elctronics/some-electronic-product-one-10/2
www.xyz.example.com/elctronics/some-electronic-product-two-11/2
Any ideas please, how can I create such actionlinks randomly based on city for product ?
I really appreciate your help. Thanks.
sp00k
Participant
1916 Points
435 Posts
Re: subdomain routing based on location parameter in MVC3
Sep 13, 2012 09:48 AM|LINK
there are different options for this but global.asax is the file you need to edit
this is the default
routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new {controller = "Home", action = "Welcome", id = UrlParameter.Optional} // Parameter defaults );for your example i would use 1 controller and 1 action let's just say we go with the Home controller and the welcome action
routes.MapRoute( "Default", // Route name "{controller}/{action}/{name}-{id}/{page}", // URL with parameters new {controller = "Home", action = "Welcome", id = UrlParameter.Optional, page = UrlParameter.Optional, name = UrlParameter.Optional, category = UrlParameter.Optional } // Parameter defaults );in your homecontroller make your method like
public ActionResult Welcome(string name = "", int id = 0, int page = 0) { if (string.isnullorempty(name) && id == 0 && page == 0) { return redirecttoaction("index"); } else { get your product etc.... return view(); } }i'm not a 100% sure about this but i think this might just work out
CPrakash82
All-Star
18720 Points
2899 Posts
Re: subdomain routing based on location parameter in MVC3
Sep 13, 2012 11:02 AM|LINK
You will not need any special code for subdomain routing unless, you are falling in some special category categoru like multi tenant app.
If yes, then please read this post here, it covers those scenario.
sureshdrim
Member
2 Points
24 Posts
Re: subdomain routing based on location parameter in MVC3
Sep 13, 2012 12:00 PM|LINK
Dear Friends,
Thanks for your help. But unfortunitely still I couldn't make it. I will explanin my issue lil more with an example. If you visit http://www.quikr.com/Air-Conditioners-Coolers/y249 here you will see a long list of ads.
Action links for these ads are generated based on city as its subdomain.
Like http://pune.quikr.com/Supreme-Gold-Mini-Air-Cooler-W0QQAdIdZ92919271
as that ad is from pune city,
http://delhi.quikr.com/OLD-AIR-CONDITIONERS-BUY-AND-SELL-9810195987-9312430444-W0QQAdIdZ91516416
as this ad is from delhi and so on.
Similary I want to generate actionlinks with subdomain in it, based on city which I fetch from DB.
Any ideas please ?
sureshdrim
Member
2 Points
24 Posts
Re: subdomain routing based on location parameter in MVC3
Sep 14, 2012 06:28 AM|LINK
Hi friends..
waiting for your valuable inputs..
@sp00k, @CPrakash82.... Thanks buddy.
sureshdrim
Member
2 Points
24 Posts
Re: subdomain routing based on location parameter in MVC3
Sep 14, 2012 06:42 AM|LINK
On a page I want to list all the products from different cities. Actionlink for each product should be generated with respective city as subdomain in the URL.
Example:
On Home Page>
Product List:
1) Product one (from Mumbai) action link to generate> www.mumbai.example.com/electronics/product-one-10/
2) Product two (from delhi) action link to generate> www.delhi.example.com/electronics/product-two-11/
3) .... and so on...
Thanks.
sureshdrim
Member
2 Points
24 Posts
Re: subdomain routing based on location parameter in MVC3
Sep 18, 2012 07:00 AM|LINK
Any ideas please...
Young Yang -...
All-Star
21742 Points
1825 Posts
Microsoft
Re: subdomain routing based on location parameter in MVC3
Sep 19, 2012 08:59 AM|LINK
In your global.asax file, you could add this in the RegisterRoutes section:
routes.Add("DomainRoute", new DomainRoute( "{city}.example.com", "{product}/{name}-{id}/{page}", new { controller = "Product", action = "List", id = "" } ));I would suggest you read the article that CPrakash post to you carefully.
Hope this helpful
Regards
Feedback to us
Develop and promote your apps in Windows Store
razin.memon
Member
2 Points
4 Posts
Re: subdomain routing based on location parameter in MVC3
Sep 19, 2012 09:30 AM|LINK
as soon as destination page is loaded get ur url(using ajax) break it and put the parts in viewbag and then search the database according ly in either view or JQuery it self.
Software Engineer in R&D at Insigno Quipment Technologies (India) Pvt Ltd
sureshdrim
Member
2 Points
24 Posts
Re: subdomain routing based on location parameter in MVC3
Sep 25, 2012 03:19 PM|LINK
Thanks..Young, Razin.. I hope Young's solution will solve my issue.. Will let u know once I am done..
Thanks a lot.