SkipLinkText属性及其问题

最近网站的异常捕捉器老是捕捉到如下错误:
System.Security.Cryptography.CryptographicException: 填充无效,无法被移除。
   在 System.Security.Cryptography.RijndaelManagedTransform.DecryptData(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[]& outputBuffer, Int32 outputOffset, PaddingMode paddingMode, Boolean fLast)
   在 System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)
   在 System.Security.Cryptography.CryptoStream.FlushFinalBlock()
   在 System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Boolean useValidationSymAlgo)
   在 System.Web.UI.Page.DecryptString(String s)
   在 System.Web.Handlers.AssemblyResourceLoader.System.Web.IHttpHandler.ProcessRequest(HttpContext context)
   在 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   在 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
分析其HTTP_REFERER,是来源于百度的快照页面,经分析百度的快照保存的页面中含有如下代码:
<img alt="Skip Navigation Links" height="0" width="0" src="/WebResource.axd?d=2CKFSExFft48UuCBt3w1pA2&amp;t=632889116642854495" style="border-0px;" />
原因就出在"/WebResource.axd?d=2CKFSExFft48UuCBt3w1pA2&amp;t=632889116642854495"这里,把它构造成完整的URL,则会获取同上一样的异常错误,因为WebResource.axd动态生的资源已经不存在了,但百度快照上保存的页面是不会更新的,所以从该页面访问的页面都会有这种异常出现,虽然不出现页面访问不到的情况,但是该来源很多,影响了对其它的异常现象的分析,所以也得把这个问题给解决掉。

上述html代码生成的地方是由SiteMapPath内部生成的,查阅了MSDN及反射查看了SiteMapPath的实现代码,发现在SiteMapPath的呈现阶段动态输出了一个图片资源:
protected internal override void RenderContents(HtmlTextWriter writer)
{
      bool flag1 = !string.IsNullOrEmpty(this.SkipLinkText) && !base.DesignMode;
      string text1 = this.ClientID + "_SkipLink";
      if (flag1)
      {
            writer.AddAttribute(HtmlTextWriterAttribute.Href, "#" + text1);
            writer.RenderBeginTag(HtmlTextWriterTag.A);
            writer.AddAttribute(HtmlTextWriterAttribute.Alt, this.SkipLinkText);
            writer.AddAttribute(HtmlTextWriterAttribute.Height, "0");
            writer.AddAttribute(HtmlTextWriterAttribute.Width, "0");
            writer.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, "0px");
            writer.AddAttribute(HtmlTextWriterAttribute.Src, base.SpacerImageUrl);
            writer.RenderBeginTag(HtmlTextWriterTag.Img);
            writer.RenderEndTag();
            writer.RenderEndTag();
      }
      base.RenderContents(writer);
      if (flag1)
      {
            writer.AddAttribute(HtmlTextWriterAttribute.Id, text1);
            writer.RenderBeginTag(HtmlTextWriterTag.A);
            writer.RenderEndTag();
      }
}
再查看了一个SpacerImageUrls的实现
internal string SpacerImageUrl
{
      
get
      
{
            
this.EnsureOccasionalFields();
            
if (this._occasionalFields.SpacerImageUrl == null)
            
{
                  
this._occasionalFields.SpacerImageUrl = this.Page.ClientScript.GetWebResourceUrl(typeof(WebControl), "Spacer.gif");
            }

            
return this._occasionalFields.SpacerImageUrl;
      }

}
确实,this.Page.ClientScript.GetWebResourceUrl调用了一个内置的图片资源,这样SiteMapPath呈现的代码中就会出现WebResource.axd的引用,接着再分析一下生成图片资源的条件: !string.IsNullOrEmpty(this.SkipLinkText) && !base.DesignMode;
这里就找到了一个属性SkipLinkText,只要把这个属性设置为空值就不会再呈现图片资源了,这个属性干什么的?查一下MSDN吧,

SkipLinkText属性是SiteMapPathTreeViewMenu 站点导航控件共有的一个属性,它的功能是"网站的每个网页上通常都使用站点导航控件。在每次访问网页和每次回发时,屏幕读取器和其他辅助设备都会朗读导航控件中的文字。用该属性可以跳过后续页或同一页面的不同视图上的重复信息。" 可以一般是用不着,所以这里就把这个属性设置为SkipLinkText=""就可以了。
原文地址:https://www.cnblogs.com/chenjunbiao/p/1760247.html