[英]How can i hide the Request parameter fields in url using MVC?
I am using the following to redirect and call an api: In my action method I have the following:我正在使用以下内容重定向并调用 api: 在我的操作方法中,我有以下内容:
if (token != null)
{
return Content($"https://localhost:1234/user/UserTokenLogin?token={myToken}");
}
Now i can see the token in the url.现在我可以在 url 中看到令牌。 Is there a way I can hide this parameter field but still extract it on the destination api?
有没有办法可以隐藏此参数字段但仍将其提取到目标 api 上?
You need to apply an encode/decode procedure.您需要应用编码/解码程序。 I'll give you an example with Base64 encoding but you could find more secure algorithms if you want.
我会给你一个 Base64 编码的例子,但如果你愿意,你可以找到更安全的算法。
public string Encode(string strToEncode)
{
byte[] encodedVal = System.Text.Encoding.UTF8.GetBytes(strToEncode);
return Convert.ToBase64String(encodedVal);
}
public string Decode(string strToDecode)
{
byte[] decodedVal = Convert.FromBase64String(strToDecode);
return System.Text.Encoding.UTF8.GetString(decodedVal);
}
Then you can apply this as below.然后你可以如下应用它。
if (token != null)
{
var encodedToken = Encode(myToken);
return Content($"https://localhost:1234/user/UserTokenLogin?token={encodedToken}");
}
public ActionResult UserTokenLogin(string token){
var decodedToken = Decode(token);
//do other stuff.
}
You can use with header parameters.您可以使用 header 参数。 it is usually used in the header.
它通常用于 header。
Response.Headers.Add("AuthToken", "token");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.