问题
in my master page there is a login status when i click on it the page is redirected to login page.now i want to create login control in the home page itself so that users dont have to visit loginpage again and again..i guess i cant create the login control in the masterpage .it has to be in the default page but then how can i put that control on the top of the page . i have also used login control in masterpage but then my other control ion login page doesnt work properly
回答1:
You can add a Login control to your master page by adding something like this to the markup
<asp:Login runat="server" ID="MyLoginControl" />
Or my dragging the Login control onto the master page's designer from the Toolbox.
To hide the login control when the user is logged in, add this code to the master page code-behind:
if (Page.User.Identity.IsAuthenticated)
{
MyLoginControl.Visible = false;
}
回答2:
Ok, let me make the following assumptions.
Currently you have:
- one masterpage
- one default page (of course)
- one login page
- bunch of other pages
You want to have:
- one masterpage (with login control)
- one default page (with a main login control)
- no login page
- bunch of other pages
My suggestion:
Option 1
- one masterpage (with login control at the top of page)
- one default page (with a main login control NOT using the materpage)
Option 2
- one masterpage (with login control at the top of page that can be hidden)
- one default page (with a main login control and hiding the masterpage's logincontrol)
Option 3
- one masterpage A (without login control)
- one masterpage B using masterpage A (with login control at the top of page)
- one default page (with a main login control using masterpage B)
- bunch of other pages (using masterpage A)
回答3:
You can add a Login control to your master page by adding something like this to the markup
<asp:Login runat="server" ID="MyLoginControl" />
来源:https://stackoverflow.com/questions/1885708/how-can-i-insert-login-control-on-the-top-of-default-page