阅读后的数据提交给ASP.Net表 [英] Read Post Data submitted to ASP.Net Form

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

问题描述

我在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登录表单页面,在Page_Load事件presumably背后的C#code ++做的,是检查页面的请求中包含用户名和密码值为在过去了。如果是的话那么我需要阅读这些价值观念,处理登录,如果有人点击了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是在姓名发帖页面上的控件的

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

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