简体   繁体   English

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

[英]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;
    }
}

Learn more 学到更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以使用动态重定向HttpContext.Current.Request吗? - can I use dynamic to redirect HttpContext.Current.Request? HttpContext.Current.Request在外部C#类中导致空对象引用 - HttpContext.Current.Request resulting in null object reference in Outer C# class C#Web API模拟HttpContext.Current.Request测试文件上传 - C# Web API Mock HttpContext.Current.Request to test file upload 生产中的HttpContext.Current.Request为null - HttpContext.Current.Request null in production 在HttpContext.Current.Request中模拟ServerVariables - Mock ServerVariables in the HttpContext.Current.Request HttpContext.Request或HttpContext.Current.Request URL中是否缺少“#”字母? - '#' letter is missing in HttpContext.Request or HttpContext.Current.Request url? 如何获取超过1000个html控件值的HttpContext.Current.Request? - how can i get HttpContext.Current.Request of more than 1000 html controls value? HttpControllerContext.Request和HttpContext.Current.Request之间的区别 - Difference between HttpControllerContext.Request and HttpContext.Current.Request HttpContext.Current.Request和Page.Request中的Url.Host - Url.Host in HttpContext.Current.Request and Page.Request 带有Angular UI路由器的HttpContext.Current.Request - HttpContext.Current.Request with Angular ui-router
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM