Note that there are some explanatory texts on larger screens.

plurals
  1. POEdit HTML Meta Tag w/ ASP.NET
    primarykey
    data
    text
    <h3>Question</h3> <p><hr /> Hello All,</p> <p>I'm trying to build a quick and easy ASP.NET page that redirects a user to a new URL using a meta redirect. Only trouble is that I need to also pass along the GET values of the current request. I've found a way to do this programatically in the code behind using the HtmlMeta object. However, I'd like to avoid using the code behind and just put this code directly into the ASPX page.</p> <p>Here is what I have so far:</p> <pre> <code> &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" &gt; &lt;head runat="server"&gt; &lt;title&gt;Untitled Page&lt;/title&gt; &lt;meta http-equiv="refresh" content='10;url=http://contact.test.net/main.aspx?&lt;%=Request.QueryString.ToString()%&gt;' /&gt; &lt;/head&gt; &lt;/html&gt; </code> </pre> <p><br /> ......However, this spits out the following meta tag: &lt;meta http-equiv="refresh" content="10;url=<a href="http://contact.test.net/main.aspx?&lt;%=Request.QueryString.ToString()%" rel="nofollow noreferrer">http://contact.test.net/main.aspx?&lt;%=Request.QueryString.ToString()%</a>>" /></p> <p>So is there any way to escape the attribute so the ASP.NET code actually executes?</p> <p>Thank you in advance for your help.<br /><br /><br /></p> <h3>Solution 1</h3> <p><hr /> For the time being, I have fixed my problem by removing the quotes from the HTML attribute. Thus making the meta tag the following:</p> <pre> <code> &lt;meta http-equiv="refresh" content=10;url=http://contact.test.net/main.aspx?&lt;%=Request.QueryString.ToString()%&gt; /&gt; </code> </pre> <p><br /> Although this fixes the issue, I'd be curious if anyone knows of a more correct way to do it where I could escape the literal quotes of the HTML attribute. <br /><br /><br /></p> <h3>Solution 2 (Final Chosen Solution)</h3> <p><hr /> Per the much appreciated advise of Scott, I decided to go ahead and do this from the code behind. For anyone who is curious how this was implemented:</p> <pre> <code> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim nRef As String = Request.QueryString("n") Dim sRef As String = Request.QueryString("s") Dim contentAttrBuilder As New StringBuilder("0;http://contact.cableone.net/main.aspx") contentAttrBuilder.Append("?n=") contentAttrBuilder.Append(nRef) contentAttrBuilder.Append("&s=") contentAttrBuilder.Append(sRef) Dim metaRedirect As New HtmlMeta() metaRedirect.HttpEquiv = "refresh" metaRedirect.Content = contentAttrBuilder.ToString() Me.Header.Controls.Add(metaRedirect) End Sub </code> </pre> <p>Thanks,<br /> Chris</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload