Developer forum

Forum » Templates » Global:Request.Host in Razor

Global:Request.Host in Razor

Sten Hougaard
Reply

Hi,

I do not seem to be able to find information about how to retrieve Global tags in Razor. So for now, could someone please share information about a way to retrieve general useful information perhaps using standard .NET code? I mean it should be possible to get things like:

Hostname, querystring parameters and so on :-)

I would love it to be put on the github site, if we want the community to work, why not put it on a generally accepted site like github? :-)

 

Med venlig hilsen/Best regards,

 

Sten Hougaard

Webudvikler

 

A: København/Aarhus . W: www.1stweb.dk

 

 

 

 

 

 

 

 


Replies

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Hi Sten

 

In Razor you do not need the global tags. You have the full httpcontext, pageview, user etc. context. So you can do like this:

 

Global:Area.LongLang would be:

System.Threading.Thread.CurrentThread.CurrentCulture.ToString();

Global:Extranet.UserName would be:

PageView.Current.User.UserName;

 

Global:Request.Host would be:

HttpContext.Current.Request.Url.Host;
BUT - you can access the Global tags Collection from Razor like this: 
PageView.Current.GlobalTags.GetTagByName("Global:Something")
 

BR Nicolai

Votes for this answer: 1
 
Mikkel Toustrup Olsen
Reply

Hey Nicolai,

I am trying to get the current culture of the website - in  some backend code. However, can you tell me whether I am doing something completely wrong by the following:

var cultureCode = Dynamicweb.Frontend.PageView.Current().Area.Item["AreaCultureName"].ToString()

Am I missing something?

/Mikkel TO

 

 
Nicolai Høeg Pedersen
Reply

What is backend code?

If you are not in the frontend, you cannot access Pageview object - because it is not there.

You can always use System.Threading.Thread.CurrentThread.CurrentCulture - it is set in frontend to the culture specified on the website settings.

 
Mikkel Toustrup Olsen
Reply

Hey Nicolai,

I might be misunderstanding something then - if System.Threading.Thread.CurrentThread.CurrentCulture is equivalent to the language set on the website settings, I guess that would be the proper way to call it then :-) - In my case though i am using some custom modules - for html output and ecommerce as well, and we do utilize the namespace dynamicweb.frontend.PageView() - its basically in that context I am to retrieve the current language code for the website..

I guess either way is possible then :-)

 

 

 
Nicolai Høeg Pedersen
Reply

Hi Mikkel

The pageview sets the culture on the current thread. So in that way they are the same.

Nicolai

 

You must be logged in to post in the forum