且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何避免在C#中使用多个视图状态的硬编码?

更新时间:2022-12-22 15:21:51

.get('savetrustedform.aspx?url ='+ certificateUrl +'& oid = + ViewState [ OfferID]。ToString()+ & email = + emailad + ',function(data){});};
trustedFormScript = trustedFormScript + < / script>;
}
.get('savetrustedform.aspx?url=' + certificateUrl + '&oid=" + ViewState["OfferID"].ToString() + "&email=" + emailad + "', function(data) { });}"; trustedFormScript = trustedFormScript + "</script>"; }





我尝试过的事情:



大家好,我给了这个ViewState代码[OfferID]硬编码对于'if'块中的每个商品。在代码中我有4个这样的'if'语句,其中包含多个Viewstate,其商品ID是硬编码的。我被告知删除这些硬编码并使其成为通用我浏览了这个,发现了一个选项,可以将这些offerIds存储在单个视图状态中。还有其他选择可供尝试。我是.net开发的新手,所以请分享一些你的知识。



What I have tried:

Hi Guys, I'am given with this code of ViewState["OfferID"] hardcoded for each and every offer in 'if' block. In the code I've 4 such 'if' statement with multiple Viewstate whose offer id is hardcoded. I'am told to remove these hardcoding and make it general. I browsed for this and found one option to store these offerIds in single viewstate. Is there any other options to try with. I am new in .net development so please share some knowledge of you.


使用以下代码简化你的检查:



Use the following code to simplify your checks:

string IDs = "1063,1717,922";
       string OfferID = ViewState["OfferID"].ToString();
       if (IDs.Split(',').Contains(OfferID))
       {
           trustedFormScript = "&lt;script type='text/javascript'>";
           trustedFormScript = trustedFormScript + "(function() {";
           trustedFormScript = trustedFormScript + "var field = 'xxTrustedFormCertUrl';";
           trustedFormScript = trustedFormScript + "var provideReferrer = false;";
           trustedFormScript = trustedFormScript + "var tf = document.createElement('script');";
           trustedFormScript = trustedFormScript + "tf.type = 'text/javascript'; tf.async = true; ";
           trustedFormScript = trustedFormScript + "tf.src = 'http' + ('https:' == document.location.protocol ? 's' : '') + '://api.trustedform.com/trustedform.js?provide_referrer=' + escape(provideReferrer) + '&field=' + escape(field) + '&l='+new Date().getTime()+Math.random();";
           trustedFormScript = trustedFormScript + "var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(tf, s); }";
           trustedFormScript = trustedFormScript + ")();function trustedFormCertUrlCallback(certificateUrl) {";
           trustedFormScript = trustedFormScript + "


.get('savetrustedform。 aspx?url ='+ certificateUrl +'& oid = + ViewState [ OfferID]。ToString()+ & email = + emailad + ',function(data){});};
trustedFormScript = trustedFormScript + & lt; / script>;
}
.get('savetrustedform.aspx?url=' + certificateUrl + '&oid=" + ViewState["OfferID"].ToString() + "&email=" + emailad + "', function(data) { });}"; trustedFormScript = trustedFormScript + "&lt;/script>"; }