读取提交到 ASP.Net 表单的 Post 数据 [英] Read Post Data submitted to ASP.Net Form

查看:28
本文介绍了读取提交到 ASP.Net 表单的 Post 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 asp.net 应用程序中有一个有效的登录表单.带有用户名和密码文本框以及用于处理登录的按钮的标准内容.工作正常.

I have a working login form in an asp.net application. Standard stuff with a username and password text box and a button to process the login. Works fine.

我有一个新要求,允许用户从一个单独的纯 html 页面输入用户名和密码,该页面不属于我的 asp.net 应用程序的一部分.我计划使用标准的 html - 表单、输入、提交按钮等来实现这一点.表单操作将是我的 asp.net 登录页面的 URL,它的方法将是 POST.

I have a new requirement to allow the user to input the username and password from a separate plain html page that is not a part of my asp.net application. I plan on achieving this using standard html - form, input, submit button etc. The form action will be the URL of my asp.net login page and its method will be POST.

我想在 asp.net 登录表单的 C# 代码隐藏页面中做的事情,大概是在 Page_Load 事件中,是检查页面请求是否包含传入的用户名和密码值.如果是然后我需要读取这些值并处理登录,就像有人点击了 asp.net 页面上的登录按钮一样.如果没有,那么我会像往常一样显示登录表单.

What I want to do in the C# code behind page of the asp.net login form, presumably in the Page_Load event, is to check if the request for the page contains a username and password value being passed in. If it does then I need to read those values and process the login as if someone had clicked the login button on the asp.net page. If not then I will display the login form as usual.

我如何检查页面请求中的用户名和密码值是否存在并读取.

How do I check for the existence of, and read, the username and password values in the request for my page.

推荐答案

阅读 Request.Form NameValueCollection 并相应地处理您的逻辑:

Read the Request.Form NameValueCollection and process your logic accordingly:

NameValueCollection nvc = Request.Form;
string userName, password;
if (!string.IsNullOrEmpty(nvc["txtUserName"]))
{
  userName = nvc["txtUserName"];
}

if (!string.IsNullOrEmpty(nvc["txtPassword"]))
{
  password = nvc["txtPassword"];
}

//Process login
CheckLogin(userName, password);

... 其中txtUserName"和txtPassword"是发布页面上控件的名称.

... where "txtUserName" and "txtPassword" are the Names of the controls on the posting page.

这篇关于读取提交到 ASP.Net 表单的 Post 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆