Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# HttpRequest.ServerVariables[“http用户代理”与HttpRequest.UserAgent之间的问题_C#_Asp.net - Fatal编程技术网

C# HttpRequest.ServerVariables[“http用户代理”与HttpRequest.UserAgent之间的问题

C# HttpRequest.ServerVariables[“http用户代理”与HttpRequest.UserAgent之间的问题,c#,asp.net,C#,Asp.net,我有以下代码: <p> <b>You are browsing this site with:</b> <% Response.Write(Request.ServerVariables["http_user_agent"]); %> <br/> <b>Or with Request.UserAgent:</b> <% Request.UserAgent.Trim()

我有以下代码:

<p>
    <b>You are browsing this site with:</b>
    <% Response.Write(Request.ServerVariables["http_user_agent"]); %>
    <br/>
    <b>Or with Request.UserAgent:</b>
    <% Request.UserAgent.Trim(); %>
</p>

您正在使用以下工具浏览此网站:

或使用Request.UserAgent:

第一个在浏览器中正确显示,但第二个(
Request.UserAgent
)未显示。为什么?另外,如果我在
Page\u Load
方法中写入第二个,那么它后面的代码也可以正常工作。为什么第二个在
Page\u Load
中工作,但不在
p
标记中工作。同样基于Microsoft和answer,两者应相同:

在ASP.NET中,您可以访问Request.ServerVariables集合,或使用new Request.UserAgent属性检索HTTP_USER_AGENT头值


正如您所提到的,两者都将返回相同的文本。但是您错过了
响应。请在第二个代码中写入
,尝试如下操作

<p>
    <b>You are browsing this site with:</b>
    <% Response.Write(Request.ServerVariables["http_user_agent"]); %>
    <br/>
    <b>Or with Request.UserAgent:</b>
    <% Response.Write(Request.UserAgent.Trim()); %>
</p>

您正在使用以下工具浏览此网站:

或使用Request.UserAgent: