asp.net - 删除 ASP.NET HTML 页面标题中的多余空格?

标签 asp.net vb.net

我有一个问题。

我使用 VB.NET 将页面的标题值指定为 page.title = "a"但是当我运行页面并查看页面 View 源时,我发现它显示为 <title> a </title>

问题是我想删除标题标签之间的所有空格,它显示如下 <title>a</title>

提前致谢!

最佳答案

据我所知,这只是 ASP.NET 渲染的一个怪癖(bug?)。

不久前我自己也遇到过这个问题,并在这里找到了这个修复:Weird white space in title tag 。如果它让您烦恼,只需将其粘贴到页面代码中即可修复它:

Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)

    Dim stringWriter As New System.IO.StringWriter()
    Dim htmlWriter As New HtmlTextWriter(stringWriter)
    MyBase.Render(htmlWriter)
    Dim html As String = stringWriter.ToString()
    Dim t1 As Integer = html.IndexOf("<title>")
    Dim t2 As Integer = html.IndexOf("</title>") + 8
    Dim newTitleTag As String = html.Substring(t1, t2 - t1)
    html = html.Replace(newTitleTag, String.Format("<title>{0}</title>", Me.Title))

    writer.Write(html)

End Sub

关于asp.net - 删除 ASP.NET HTML 页面标题中的多余空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5577121/

相关文章:

c# - 优化代码: Linq and foreach loop 15k records

c# - 如何在 asp.net 列表框中获取多个选定项并显示在文本框中?

vb.net - Reporting Services 2008 表达式中的 vbtab

asp.net - 将新记录添加到 GridView 但不应更新数据库

c# - html编码空间的HtmlDecode不是空间

javascript - 如何将文本框值设置为隐藏字段

c# - 操作过滤器中的 session 变量

asp.net - Azure 表存储 session 状态提供程序

javascript - ID、唯一 ID、客户端 ID、唯一客户端 ID、静态客户端 ID?

c# - 我的C#程序需要使用VB文件中的方法,如何调用这个方法?