Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to assign the encrypted value into session storage in .cshtml file.(我正在尝试将加密的值分配给.cshtml文件中的会话存储。)

but I couldn't.(但我做不到) I am getting a different error each time.(我每次都会收到一个不同的错误。) Error I got: Uncaught SyntaxError: Unexpected token ')' , Uncaught SyntaxError: Invalid left-hand side in assignment(我收到的错误: 未捕获的SyntaxError:意外的令牌')'未捕获的SyntaxError:分配中的左侧无效) <script type="text/javascript"> @{ string createApplicationRequestPKey =Request.QueryString["cpk"]; if(createApplicationRequestPKey != null) { @:sessionStorage.setItem('CreateApplicationRequestPKey', @createApplicationRequestPKey); @:location.href = '/'; } }</script> Sample request :url?cpk=U2FsdGVkX1+S3rsDcNeHuP5g6LokgGx9/xV1QcSVR+g=(样本请求:url?cpk = U2FsdGVkX1 + S3rsDcNeHuP5g6LokgGx9 / xV1QcSVR + g =)   ask by Arun Kumar translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
291 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try using the encodeURI function in javascript :(尝试在javascript使用encodeURI函数:)

string createApplicationRequestPKey = encodeURI(Request.QueryString["cpk"]); If you are using c# on the server side use base64 or urlencode:(如果在服务器端使用c# ,请使用base64或urlencode:) public static string Base64Encode(string plainText) { var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText); return System.Convert.ToBase64String(plainTextBytes); } public static string Base64Decode(string base64EncodedData) { var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData); return System.Text.Encoding.UTF8.GetString(base64EncodedBytes); } string encoded = System.Web.HttpUtility.UrlEncode(cpk);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...