asp.net web service login - asp.net

I have a login system using forms authentication, the problem is I want login and register links if the user is not logged in and if the user is logged in I want welcome username and a logout link. My website is using master page for a consistent layout so I am assuming all the code will go in there..
I am thinking on the page load I will have something like this:
if (User.Identity.IsAuthenticated)
{
label1.Text = User.Identity.Name;
}
But I get user does not exist in the current context.
Thanks

Thanks to filbert. Here is the answer:
<asp:LoginView ID="RegisterLink" runat="server">
<AnonymousTemplate>
<div class="titleRegistration">
Register or
</div>
</AnonymousTemplate>
<LoggedInTemplate>
<div class="titleRegistration">
Hi <b><asp:LoginName ID="LoginName1" runat="server" />!</b>
</div>
</LoggedInTemplate>
</asp:LoginView>
<asp:LoginStatus ID="lsGeneral" runat="server" LogoutPageUrl="/Users/Logout.aspx" />
Thanks Filbert.

Related

call login page and register page in popup window in asp.net

i have to design an website use asp.net
in this web site we have to use login and register
i use this code in master page
<asp:LoginView ID="Log_view" runat="server">
<AnonymousTemplate >
<span class="log_txt">Hi Guset! </span>
Rigster
Login
</AnonymousTemplate>
<LoggedInTemplate>
<asp:LoginName ID="Log_name" runat="server" CssClass="log_txt" FormatString="Hi, {0}!"/>
<asp:LoginStatus ID="LoginStatus1" runat="server" LogoutText="Logout" CssClass="log_lnk" LogoutPageUrl="~/Default.aspx" LogoutAction="Redirect" OnLoggingOut="LoginStatus1_LoggingOut" /> </LoggedInTemplate>
</asp:LoginView>
and its work without any problem, but the login page and register page will display normal, i want to display in popup window.
in other page i use this script to call page in popup window use AjaxControlToolkit and its work fine
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<span>
<a href="#" id="Rig_log" runat="server" > Rigister | Login </a>
</span>
<cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panl1" TargetControlID="Rig_log" CancelControlID="btn_close" BackgroundCssClass="popup_Background">
</cc1:ModalPopupExtender>
<cc1:DragPanelExtender ID="Image1_DragPanelExtender" runat="server"
Enabled="True" TargetControlID="Panl1" DragHandleID="Panl1">
</cc1:DragPanelExtender>
<asp:Panel ID="Panl1" runat="server" CssClass="Popup" align="center" style = "display:none">
<div id="popup_header"> <span>Register | Login </span><a href="#" ID="btn_close" runat="server" > X </a></div>
<div id="popup_content"> <iframe id="irm1" src="Register_login.aspx" runat="server"></iframe></div>
</asp:Panel>
my issue is , how i can call login page and register page in popup, i try but it's not working
thanks
Hanashi,
You can try out java script below like this.
window.open(your page name);
Dinesh Nagrale

How to Authenticate Login form without using asp controls

I have put together a really nice Login page in which I am using HTML input tags for my username, password, and login button. I have two different login forms, one for each type of user (student user, and business user). I have never authenticated against a database so I assumed my method would be easy to execute. After scouring the web for easy methods to implement with what I already had I found it nearly impossible to figure out how to accomplish my goal without having to use asp:login control. Begrudgingly, I scrapped what I had and threw in the asp:login control. My problem is, that it was a pain to implement (creating stored procedures, and messing with the web.config), it looks hideous as it doesn't not conform with the CSS I had previously written, and the FormsAuthentication I am using only allows me to redirect one user after login (to the home portal upon succesful login, and back to the login page if login failed.) using the authentication Forms mode in my Web.config:
<forms defaultUrl="~/InteriorStudentPortal.aspx" loginUrl="~/ExteriorLogin.aspx" slidingExpiration="true" timeout="2880"></forms>
Since I have two users I need to redirect based on what user is logging in. Here is a sample of the asp:login control that I have been using:
<asp:Login ID="Login1" runat="server" CssClass="Login" OnAuthenticate= "ValidateStudent" Width="313px"></asp:Login>
Along with the back code:
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
Imports System.Web.Security
Partial Class ExteriorLogin
Inherits System.Web.UI.Page
Protected Sub ValidateStudent(sender As Object, e As AuthenticateEventArgs) Handles Login1.Authenticate
Dim studentId As Integer = 0
Dim constr As String = ConfigurationManager.ConnectionStrings("DatabaseConnectionString").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("Validate_Student")
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("#Username", Login1.UserName)
cmd.Parameters.AddWithValue("#Password", Login1.Password)
cmd.Connection = con
con.Open()
studentId = Convert.ToInt32(cmd.ExecuteScalar())
con.Close()
End Using
Select Case studentId
Case -1
Login1.FailureText = "Username and/or password is incorrect."
Exit Select
Case -2
Login1.FailureText = "Account has not been activated."
Exit Select
Case Else
FormsAuthentication.RedirectFromLoginPage(Login1.UserName, Login1.RememberMeSet)
Exit Select
End Select
End Using
End Sub
End Class
My goal is to either continue using the asp:login controls and figure out how to allow for multiple user redirects after login....OR preferably, authenticate without using the asp:login and use my original HTML and CSS. Here is what I had prior to using the asp control:
<%-- STUDENT LOGIN --%>
<div class="student_login">
<div id="wrapper">
<form name="login-form" class="login-form" action="" method="post">
<div class="header">
<h1>Student Login</h1>
<span>Sign in below to login to start showing your skills, earning money, and gaining valuable experience...and did I mention earning MONEY.</span>
</div>
<div class="content">
<input name="username" type="text" class="input username" placeholder="Username" />
<input name="password" type="password" class="input password" placeholder="Password" />
</div>
<div class="footer">
<input type="submit" name="submit" value="Login" class="button" />
Register
</div>
</form>
</div>
</div><!--close student_login-->
NOTE: This section of code is written within a content placeholder. The master page does have a <form runat="server"></form> tag encompassing the body of the page. I do not have any back code for this particular method as I really have no clue how to authenticate without using the asp:login control and FormsAuthentication. Can someone please help me understand how to accomplish authenticating without the asp:login so that I can keep my nicely designed Login form? And please be generous or kind with the comments/explanation, this is my first login form so I have no experience doing this.
You can use the LayoutTemplate of the Login control to do what you want.
The trick is that you need to use a Literal with the ID of FailureText, the user field is a TextBox with ID of UserName, and another TextBox with the ID of Password.
You also will need to trigger a Login command which could be a Button.
This allows you to customize your own layout, I've done this a few times myself. Below is a quick copy/paste untested version with your HTML as an example.
See an MSDN reference at https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.login.layouttemplate.aspx
<asp:Login ID="Login1" runat="server"
OnAuthenticate="ValidateStudent"
Width="100%">
<LayoutTemplate>
<div class="student_login">
<div id="wrapper">
<asp:Literal ID="FailureText" runat="server"></asp:Literal>
<asp:ValidationSummary ID="vsLogin" runat="server" ValidationGroup="Login" />
<div class="header">
<h1>Student Login</h1>
<span>Sign in below to login to start showing your skills, earning money, and gaining valuable experience...and did I mention earning MONEY.</span>
</div>
<div class="content">
<asp:TextBox id="UserName" runat="server" CssClass="input username" placeholder="Enter your username"></asp:TextBox>
<asp:RequiredFieldValidator id="rfvUserName" runat="server"
ControlToValidate="UserName"
Display="None"
ErrorMessage="Username is required"
ValidationGroup="Login">
</asp:RequiredFieldValidator>
<asp:TextBox id="Password" runat="server" CssClass="input password" TextMode="Password" placeholder="Password"></asp:TextBox>
<asp:RequiredFieldValidator id="rfvPassword" runat="server"
ControlToValidate="Password"
Display="None"
ErrorMessage="Password is required"
ValidationGroup="Login">
</asp:RequiredFieldValidator>
</div>
<div class="footer">
<asp:Button ID="Login" runat="server" CommandName="Login" CssClass="button" Text="Login" ValidationGroup="Login" />
Register
</div>
</div>
</div>
</LayoutTemplate>
</asp:Login>

A page can have only one server-side Form tag Issue

I have a masterpage like this
<%# Master Language="C#" MasterPageFile="~/masterpages/XmasShop.master" AutoEventWireup="true" %>
<asp:Content ContentPlaceHolderID="cphContents" runat="server">
<asp:LoginView runat="server" ID="lview1">
<LoggedInTemplate>
<div class="confirmation-cantainer">
<div class="confirm-01">
<form runat="server">
<umbraco:Macro Alias="[Xmas]ShopConfirm" runat="server"></umbraco:Macro>
</form>
</div>
</div>
</LoggedInTemplate>
</asp:LoginView>
</asp:Content>
<asp:Content ContentPlaceHolderID="cphAuthenticationPane" runat="server">
<asp:LoginView runat="server" ID="lview12">
<LoggedInTemplate>
<form runat="server">
<asp:LoginStatus ID="lslougout" runat="server" Style="float: right; color: #003263; text-decoration: none;" text="Logout"></asp:LoginStatus>
</form>
</LoggedInTemplate>
</asp:LoginView>
</asp:Content>
And you can see I have two form tags in it,but both are seperate not nested.Still I am getting an error
A page can have only one server-side Form tag.
Can any one suggest me a solution.When I tried to remove one of the forms its throwing an error elements must be inside a form tag and when I add form above error.
Use the following tutorial to set up two form tags and be able to toggle them on and off, as required:
http://jerschneid.blogspot.com/2007/03/hide-form-tag-but-leave-content.html
One solution is to have the login information on a separate page. You could also look into using an iframe.
This error occurred due to use of more than one
<form runnat="server">
tag.
Remove one of the form tag.
This would be more clear by visiting this link

asp login - open a new window if authentication is successful

I need to open a new window if the authentication of a users login is successful. is there an easy way to have the DestinationPageUrl open in a new window using something like target="_blank" ? below is my code:
<body>
<form id="form1" runat="server">
<div>
<br />
<asp:LoginView ID="LoginView1" runat="server">
<AnonymousTemplate>
<asp:Login ID="Login1" runat="server" DestinationPageUrl="~/Public/Index.aspx" OnAuthenticate="Login1_Authenticate">
</asp:Login>
</AnonymousTemplate>
<LoggedInTemplate>
Welcome User
</LoggedInTemplate>
</asp:LoginView>
<br />
</div>
</form>
</body>
I would code the page with two controls, one for login. Once the login is successful, hide the login and display your form. No redirect necessary.

How can I add an invitation dialog to my facebook application (using ASP.Net)

I'm developing a facebook application, using IFrame instead of FBML. I have a main page with a sub-iFrame inside. In the inner iframe (the invitation page) I have:
<%# Register Assembly="Facebook.Web" Namespace="Facebook.Web.FbmlControls" TagPrefix="cc1" %>
<cc1:Fbml ID="Fbml1" runat="server" Xfbml="True">
<ContentTemplate>
<cc1:RequestForm ID="RequestForm1" runat="server" Method="Post" Type="Xfbml" Xfbml="True"
Invite="True" Content="Invite your friends" Action="." Visible="True">
<ContentTemplate>
<cc1:MultiFriendSelector ID="MultiFriendSelector1" runat="server" Rows="3" Xfbml="True"
ShowBorder="True" EmailInvite="True" Bypass="Cancel" ActionText="Select Friends you want to invite">
</cc1:MultiFriendSelector>
</ContentTemplate>
</cc1:RequestForm>
</ContentTemplate>
</cc1:Fbml>
This doesn't work at all and when I view the frame source, I get:
<fb:fbml>
<fb:request-form type="Xfbml" Content="Invite your friends" action="." method="POST">
<fb:multi-friend-selector actiontext="Select Friends you want to invite" showborder="true" email_invite="true" rows="3" bypass="cancel"></fb:multi-friend-selector>
</fb:request-form>
</fb:fbml>
Any ideas and/or suggestions are very appreciated. Thanks for reading anyway

Resources