初学者的asp.net登录页面

编程入门 行业动态 更新时间:2024-10-22 13:45:32
本文介绍了初学者的asp登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道这是关于学习ASP.NET的一个基本问题,我曾在Google,StackOverflow,MSDN和CodeProject上搜索过,但结果没有找到。 我正在使用ASP.NET(C#)在2个文本框中设计页面 default.aspx 和一个按钮(用户名,密码和提交)。 登录成功后,

Response.Redirect( userprofile.aspx );

会将我重定向到该页面。 这是我的问题:在页面上 userprofile.aspx ,如果我点击链接转移到 default.aspx ,如何更改2个文本框和一个按钮(禁用或消失在页面 default.aspx )通过2个链接用户名退出? 谢谢!

解决方案

如果您想在c#中使用两个文本框创建简单的登录面板,例如emailid和密码以及Log按钮控件在'然后在你的页面中的按钮点击事件中写下面的代码 c#代码在这里 < blockquote class =quote>< div class =op > Quote:< / div> string Query =select * from tblLogin where emailid ='+ txtEmailID.Text +'and password ='+ txtPassword.Text +'; SqlDataAdapter adp = new SqlDataAdapter(Query,con); DataSet ds = new DataSet(); adp.Fill(ds); if(ds.Tables [0] .Rows.Count> 0) { lblErrorMsg.Text =成功登录; } else { lblErrorMsg.Text =EmailID /密码不正确; txtEmailID.Focus(); }< / blockquote> 完整详细信息请访问此链接....我希望此链接对您有所帮助 http:// aspdotnet-alam .COM /条/如何对创建登录页面与 - 正确的验证和记住,我的功能 - 使用 - 天冬氨酸-NET-C-夏普1.aspx

最好使用asp成员资格或身份来做这些事情,但是如果你这样做是一个学习任务,那么你可以存储用户是否使用Session登录。存储他们的ID或用户名,如果您需要知道他们是否已登录,请检查相关的会话变量是否有值。 一种方便的方式来显示\ n隐藏某些元素取决于是否有人通过身份验证是使用您可见或隐藏的占位符。

< asp:PlaceHolder ID = placeAuthenticated runat = server 可见 = false > < div > Hello <% =会话[ 用户名] %> (< asp:HyperLink ID = linkLogout runat = server NavigateUrl = 〜/ Logout.aspx > logout < / asp:HyperLink > ) < / div > < / asp:PlaceHolder > < asp:PlaceHolder ID = placeAnonymous runat = 服务器 可见 = true > < asp:按钮 ID = cmdLogin runat = server 文字 = 登录 OnClick = cmdLogin_Click / > < / asp:PlaceHolder >

b $ b

受保护 void Page_Load( object sender,EventArgs e) { if (!string。 IsNullOrWhiteSpace(( string )会话[ 用户名])) { placeAnonymous.Visible = false ; placeAuthenticated.Visible = true ; } } 受保护 void cmdLogin_Click( object sender,EventArgs e) { // 确保用户有效,如果存储他们的用户名或用户ID(或两者) // 会话[ 用户名] = user1; Response.Redirect( test.aspx); // 此页面只是为了简单而重定向到自身 }

I know that it's a basic question about learning ASP.NET, I had searched on Google, StackOverflow, MSDN and CodeProject but nothing was found for my result. I'm using ASP.NET (C#) to design a page default.aspx within 2 textboxes and a button (username, password and submit). After login successfull,

Response.Redirect("userprofile.aspx");

will redirect me to the page. Here is my question: On the page userprofile.aspx, if I click a link to move to default.aspx, "How to change 2 textboxes and a button (disable or disappear on page default.aspx) by 2 links "Hi, username" and "Logout"? Thank you!

解决方案

If you want create simple login panel in c# with two textbox like emailid and password and button control for 'Login' then write below code in button click event in your page c# Code here <blockquote class="quote"><div class="op">Quote:</div>string Query = "Select * from tblLogin where emailid='" + txtEmailID.Text + "' and password='" + txtPassword.Text + "'"; SqlDataAdapter adp = new SqlDataAdapter(Query,con); DataSet ds = new DataSet(); adp.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { lblErrorMsg.Text = "Successfully login"; } else { lblErrorMsg.Text = "EmailID/Password Incorrect"; txtEmailID.Focus(); }</blockquote> for full details go to this link ....i hope this link will helpful for you aspdotnet-alam/Article/how-to-create-login-page-with-proper-validation-and-remember-me-functionality-using-Asp-Net-C-Sharp-1.aspx

It's better to use asp membership, or identity to do these things, but if you are doing this is a learning task then you can store if the user is logged in using the Session. Store their ID or username, and if you need to know if they are logged in check to see if the relevant session variables have a value. A handy way to show\hide certain elements depending on if someone is authenticated is to use placeholders which you make visible or hidden depending.

<asp:PlaceHolder ID="placeAuthenticated" runat="server" Visible="false"> <div>Hello <%=Session["Username"] %> (<asp:HyperLink ID="linkLogout" runat="server" NavigateUrl="~/Logout.aspx">logout</asp:HyperLink>) </div> </asp:PlaceHolder> <asp:PlaceHolder ID="placeAnonymous" runat="server" Visible="true"> <asp:Button ID="cmdLogin" runat="server" Text="Login" OnClick="cmdLogin_Click" /> </asp:PlaceHolder>

protected void Page_Load(object sender, EventArgs e) { if(!string.IsNullOrWhiteSpace((string)Session["Username"])) { placeAnonymous.Visible = false; placeAuthenticated.Visible = true; } } protected void cmdLogin_Click(object sender, EventArgs e) { // ensure the user is valid, if so store their username, or userid (or both) // in the session Session["Username"] = "user1"; Response.Redirect("test.aspx"); // this page just redirects to itself for simplicity }

更多推荐

初学者的asp.net登录页面

本文发布于:2023-11-09 20:35:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573374.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:初学者   页面   asp   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!