计算ScriptResource.axd的d参数

本文介绍了一种在ASP.NET应用中实现字符串加密和解密的方法。通过反射调用System.Web.UI.Page类中的静态非公开方法EncryptString和DecryptString来完成对字符串的安全处理。这些方法可以用于保护配置文件或其他敏感信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

protected void Page_Load(object sender, EventArgs e)

{ var url= string.Format("ScriptResource.axd?d={0}", PageEncryptString("Q|~/web.config|#|xlsb"));

//var info = F.Studio.Web.Utility.MachineKeyUtil.GenerateMachineKey();

 //Response.Write("D->" + info.Decryption +":" + info.DecryptionKey +"
"); //Response.Write("V->" + info.Validation +":" + info.ValidationKey);

}

public static string PageDecryptString(string input) {

Type type = typeof(System.Web.UI.Page);

 object o = Activator.CreateInstance(type);

System.Reflection.MethodInfo mi = type.GetMethod("DecryptString", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static, null, new Type[] { typeof(string) }, null);

object result = mi.Invoke(o, new object[] { input }); return result.ToString();

}

 public static string PageEncryptString(string input)

 {

Type type = typeof(System.Web.UI.Page);

object o = Activator.CreateInstance(type); System.Reflection.MethodInfo mi = type.GetMethod("EncryptString", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static, null, new Type[] { typeof(string) }, null); object result = mi.Invoke(o, new object[] { input }); return result.ToString();

 }

1、为ScriptManager添加脚本引用,不从ScriptResource.axd中加载MicrosoftAjax.js脚本,而是直接加载 <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"> <Scripts> <asp:ScriptReference Name="MicrosoftAjax.js" ScriptMode="auto" Path="~/ScriptLibrary/System.Web.Extensions/1.0.61025.0/MicrosoftAjax.js" /> </Scripts> </asp:ScriptManager> 2、修改MicrosoftAjax.debug.js 删除 switch(Sys.Browser.agent) { case Sys.Browser.InternetExplorer:与 case Sys.Browser.Safari: 之间的脚本,替换为如下脚本: Sys.UI.DomElement.getLocation = function(element) { if (element.self || element.nodeType === 9) return new Sys.UI.Point(0,0); var clientRect = element.getBoundingClientRect(); if (!clientRect) { return new Sys.UI.Point(0,0); } var ownerDocument = element.document.documentElement; var offsetX = clientRect.left - 2 + ownerDocument.scrollLeft, offsetY = clientRect.top - 2 + ownerDocument.scrollTop; try { var f = element.ownerDocument.parentWindow.frameElement || null; if (f) { var offset = 2 - (f.frameBorder || 1) * 2; offsetX += offset; offsetY += offset; } } catch(ex) { } return new Sys.UI.Point(offsetX, offsetY); } break; 3、修改MicrosoftAjax.js 删除 switch(Sys.Browser.agent){case Sys.Browser.InternetExplorer:与 case Sys.Browser.Safari: 之间的脚本,替换为如下脚本: Sys.UI.DomElement.getLocation=function(a){if(a.self||a.nodeType===9)return new Sys.UI.Point(0,0);var b=a.getBoundingClientRect();if(!b)return new Sys.UI.Point(0,0);var c=a.document.documentElement,d=b.left-2+c.scrollLeft,e=b.top-2+c.scrollTop;try{var g=a.ownerDocument.parentWindow.frameElement||null;if(g){var f=2-(g.frameBorder||1)*2;d+=f;e+=f}}catch(h){}return new Sys.UI.Point(d,e)};break;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值