I am using C# with ASP.NET.

How do I check if a parameter has been received as a POST variable?

I need to do different actions if the parameter has been sent via POST or via GET.

推荐答案

Use this for GET values:

Request.QueryString["key"]

And this for POST values

Request.Form["key"]

Also, this will work if you don't care whether it comes from GET or POST, or the HttpContext.Items collection:

Request["key"]

Another thing to note (if you need it) is you can check the type of request by using:

Request.RequestType

Which will be the verb used to access the page (usually GET or POST). Request.IsPostBack will usually work to check this, but only if the POST request includes the hidden fields added to the page by the ASP.NET framework.

Asp.net相关问答推荐

IISExpress未在ARM64 Mac/.NET 4.8上启动

分层架构中的 ASP.NET 和实体框架 - 仅将实体框架用于 ORM

HttpRuntime.Cache[] 与 Application[]

如何使用 executeReader() 方法仅检索一个单元格的值

如何将 JQuery 与母版页一起使用?

如何防止 Azure 网站进入Hibernate 状态?

MSCharts找不到请求类型'GET'的http处理程序错误

在 Asp.net 中通过 Button 的 CommandArgument 传递多个参数

stream.CopyTo - 文件为空.网

与将 Web 应用程序保存在一个默认应用程序池中相比,拥有专用应用程序池的优缺点

如何获取 ASP.NET 应用程序的完整虚拟路径

使用 LINQ 进行递归控制搜索

在 ApiController 中添加自定义响应头

应该如何使用 RedirectToRoute?

ASP.NET MVC 2.0 JsonRequestBehavior 全局设置

要调用此方法,Membership.Provider属性必须是ExtendedMembershipProvider的实例

捕获的异常本身为 null !

在资源文件中使用 HTML

如何解决我的 ASP.Net MVC 应用程序中的 iisreset 后发生的 AntiForgeryToken 异常?

Session.Clear() 与 Session.RemoveAll()