[英]C# Use HttpContext.Current.Request Cannot get QueryString e when requested on mobile browser
This is my public method(APIUtility) 这是我的公开方法(APIUtility)
public static string GetRequestData(string key, string defaultVal)
{
if (HttpContext.Current != null && HttpContext.Current.Request != null)
{
return HttpContext.Current.Request[key] == null || HttpContext.Current.Request[key].Trim() == "" ? defaultVal : HttpContext.Current.Request[key].Trim();
}
else
{
return defaultVal;
}
}
Have the html used javascript location.href(aa.json?key=value&key1=value1....)
go to url my class funtion 让html使用的javascript location.href(aa.json?key=value&key1=value1....)
转到我的类函数的网址
In the Function aa used string getUrlValue = APIUtility.GetRequestData(key name)
get Querystring. 在函数a中,使用string getUrlValue = APIUtility.GetRequestData(key name)
获取string getUrlValue = APIUtility.GetRequestData(key name)
。
The user uses the phone browser (OppoBrowser or safari..) to jump to the server function through my html page Unable to get querystring is empty, but if using a computer is normal. 用户使用电话浏览器(OppoBrowser或safari ..)通过我的html页面跳转到服务器功能无法获取查询字符串为空,但是如果使用计算机是正常的。
Hope you can understand what I want to express. 希望你能理解我要表达的内容。
Try System.Web.HttpContext.Current.Request.QueryString
试试System.Web.HttpContext.Current.Request.QueryString
public static string GetRequestData( string key, string defaultVal ) {
try {
var ctx = System.Web.HttpContext.Current;
var value = ctx.Request.QueryString[key];
return string.IsNullOrEmpty(value) ? defaultVal : value;
} catch {
return defaultVal;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.