C# 使用HttpContext.Current.Request 在手机浏览器上请求时无法获取QueryString e

标签 c# asp.net query-string

这是我的公共(public)方法(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;
    }
}

让 html 使用 javascript location.href(aa.json?key=value&key1=value1....) 转到 url 我的类函数

在函数 aa 中使用 string getUrlValue = APIUtility.GetRequestData(key name) get Querystring。

用户使用手机浏览器(OppoBrowser或safari..)通过我的html页面跳转到服务器功能 无法获取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;
    }
}

Learn more

关于C# 使用HttpContext.Current.Request 在手机浏览器上请求时无法获取QueryString e,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53267367/

相关文章:

c# - 获取默认凭据?

elasticsearch - ElasticSearch 查询字符串的模糊查找

c# - 启用写入映射到内存的文件

c# - 如何使用 FsCheck 为可为 null 的类型生成 null?

c# - SSIS:列大小未根据查询更改

php - Laravel/PHP - 将多个值推送到查询字符串(相同参数)

json - 如何将JSON转换为angular2中的查询字符串?

c# - 写入Windows 7 "preview"窗口区域

c# - 从不同线程访问 HttpContext.Current

c# - 如何不区分大小写地使用 indexOf()?