编辑HTML Meta标签W / ASP.NET [英] Edit HTML Meta Tag w/ ASP.NET

查看:145
本文介绍了编辑HTML Meta标签W / ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



您好所有,


Hello All,

我试图建立一个用户使用元重定向一个新的URL重定向一个快速简便的ASP.NET页面。唯一麻烦的是,我还需要沿着当前请求的GET值传递。我已经找到一种方法来在背后用HtmlMeta对象code编程做到这一点。不过,我想,以避免使用code后面,只是把这个code直接插入ASPX页面。

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.

下面是我到目前为止有:

Here is what I have so far:



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <meta http-equiv="refresh" content='10;url=http://contact.test.net/main.aspx?<%=Request.QueryString.ToString()%>' />
</head>
</html>



......然而,这吐出以下meta标签:其中,META HTTP-当量=刷新内容=10; URL =的 http://contact.test.net/main.aspx?<%=Request.QueryString.ToString ()%> />

那么,有没有办法逃避的属性,这样的ASP.NET code实际执行?

So is there any way to escape the attribute so the ASP.NET code actually executes?

感谢您提前对你的帮助。


Thank you in advance for your help.




暂时,我已经从HTML属性去掉引号固定我的问题。从而使meta标签如下:


For the time being, I have fixed my problem by removing the quotes from the HTML attribute. Thus making the meta tag the following:



<meta http-equiv="refresh" content=10;url=http://contact.test.net/main.aspx?<%=Request.QueryString.ToString()%> />




虽然这个解决问题,如果有人知道更正确的方式做到这一点,我可以逃避HTML属性的文字引号我很好奇。




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.




每斯科特的多少AP preciated提醒,我决定继续前进,从code做到这一点后面。对于任何人谁是好奇,这是如何实现的:


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:



    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

谢谢,

克里斯

Thanks,
Chris

推荐答案

头标记内也许这code将是你所需要的:

Maybe this code inside the head tag will be what you need:

<%= string.Format("<meta http-equiv='refresh' content='10;url=http://contact.test.net/main.aspx?{0}' />", Request.QueryString.ToString()) %>

然而,我不会建议你做这种方式。例如,这个网址:

However, I wouldn't advise you to do it this way. For example, this URL:

http:/mysite.with.metaredirect?<script>alert('hello!!!')</script>

将扔在asp.net异常,如果你还没有禁用它的安全功能,你永远不知道,如果有人(甚至你自己)将关闭它们由于某些其他原因。


一个code-背后的按摩的查询字符串就是强烈建议!

will throw an exception in asp.net if you haven't disabled its security features, and you never know if someone (or even yourself) will turn those off for some other reason.

A code-behind massage of the querystring is strongly advised!

这篇关于编辑HTML Meta标签W / ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆