ASP.Net using base tag dinamically

Utilizzare il tag base dinamically in 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=””>

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 + "/" + "\" />"));




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


Stai commentando usando il tuo account Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. 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 )

Connessione a %s...