public ActionResult GetAccessoriesByType(RenderModel model, string id)
{
Common _common = new Common();
string brand = Request.Url != null ? _common.GetProductBrand() : BrandType.SCT;
var productSearchResultsModel = new ProductSearchResultsModel
{
Accessories = _accessoryRepository.GetAccessoriesByType(id, brand)
};
return View("~/Views/accessories.cshtml", productSearchResultsModel);
}
The code that gets the brand is:
public class Common
{
public string GetProductBrand()
{
var host = HttpContext.Current.Request.Url.Host;
if (host.Contains("sctflash"))
return BrandType.SCT;
if (host.Contains("bigrig") || host.Contains("bigrigs"))
return BrandType.BigRig;
if (host.Contains("bullydog"))
return BrandType.BullyDog;
return BrandType.SCT;
}
}
How can I ensure the Request.Url.Host contains the proper host when the same action method is accessed from two different hosts?
The reason why accessing another website was bringing back the one websites content and the Request.Url.Host had the other websites information was because I had declared OutPutCache[Duration=60] at the top of my controller. If I waited 60 seconds and then refreshed, the correct data for each website would return. Once I removed this from the controller, everything worked as expected.
How can I make the following action method thread safe?
The following two links access the same action method (they share the same document type and access the same controller and action):
http://stage.bullydog.com/Products/accessories/podmount
andhttp://stage.sctflash.com/Products/accessories/podmount
I use
Request.Url.Host
to determine the brand of products I want to return from a database. When I accesshttp://stage.bullydog.com/Products/accessories/podmount
first,Request.Url.Host
contains the valuestage.bullydog.com
, but if I then go tohttp://stage.sctflash.com/Products/accessories/podmount
,Request.Url.Host
may containstage.sctflash.com
or it may containstage.bullydog.com
.The action method that is called is:
The code that gets the brand is:
How can I ensure the
Request.Url.Host
contains the proper host when the same action method is accessed from two different hosts?You can see this in action if you go to
http://stage.bullydog.com/Products/accessories/podmount
and then go tohttp://stage.sctflash.com/Products/accessories/podmount
and refresh either one, the logo should change which means that the value returned byRequest.Url.Host
was incorrect.Also, can GetProductBrand be static and still be thread-safe in this case?
The reason why accessing another website was bringing back the one websites content and the
Request.Url.Host
had the other websites information was because I had declaredOutPutCache[Duration=60]
at the top of my controller. If I waited 60 seconds and then refreshed, the correct data for each website would return. Once I removed this from the controller, everything worked as expected.Hi Saied,
You can also setup your cache per domain.
Try to look at http://stackoverflow.com/questions/2012072/asp-net-mvc-output-cache-for-multinenant-application-vary-by-hostname-and-cultu
You need something like:
Thanks,
Alex
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.