Home > ASP.NET > ASP.Net using base tag dinamically

ASP.Net using base tag dinamically

Utilizzare il tag base dinamically in Asp.net IT_flag

Sometimes when we use Masterpage in ASP.NET  we have to specify a base URI.

In this case we can use in masterpage <base>  tag
ex: <base href=”www.eurotech.com/en/”>

For me in ASP.NET  is better to set <base> dinamically in offending page.
We can do this using the following code into the Page_Load event or better in Page_Init event:


this.Header.Controls.Add(new  LiteralControl("<base href=\"" + 
"http://" + Request.Url.Host.ToString() + Request.ApplicationPath + 
"/" + "\" />") ) ;

If you use the Url.Scheme “https” in addition to “http” Url.Scheme, it is better  to use Request.Utl.Scheme

this.Header.Controls.Add(new LiteralControl("<base href=\"" +
Request.Url.Scheme + "://" + Request.Url.Host.ToString() + 
Request.ApplicationPath + "/" + "\" />"));

It is possible to use  Request.Url.Authority instead of  Request.Url.Host

Url.Authority returns the host and port address.

this.Header.Controls.Add(new LiteralControl("<base href=\"" +
Request.Url.Scheme + "://" + Request.Url.Authority.ToString() + 
Request.ApplicationPath + "/" + "\" />"));


  1. Non c'è ancora nessun commento.
  1. No trackbacks yet.

Lascia un commento

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...

%d blogger cliccano Mi Piace per questo: