Asp.net's LoggedInTemplate never displays, only AnonymousTemplate -
i'm using microsoft visual studio 2013 build website. want master page different depending on whether 1 logged in or not. end use <loggedintemplate>
, <anonymoustemplate>
. unanswered question @ loggedintemplate not displayed, however, latter displayed, regardless of whether or not i'm logged in. code @ master page follows:
<asp:loginview id="loginview2" runat="server"> <loggedintemplate> <ul id="loggedin"> <li><asp:loginname id="loginname1" runat="server"/>user page</li> <li><asp:loginstatus id="loginstatus1" runat="server" /><a href="logout.aspx">log out</a></li> </ul> </loggedintemplate> <anonymoustemplate> <ul> <li><a href="registration.aspx">register</a></li> <li><a href="login.aspx">log in</a></li> </ul> </anonymoustemplate> </asp:loginview>
my master page's .cs page not contain code (except default lines created @ page creation). <loggedintemplate>
require code in associated .cs work? , if so, need?
my logout page, behaves differently based on whether 1 logged in or not (log out , display page if logged in; redirect login page if not logged in), works fine far have been able tell, suggesting me login procedure works fine. sure i'm login procedure, if <loggedintemplate>
not require code in .cs file, i'll post code on login , logout pages see if there problem there.
update: code in login.aspx.cs file is
protected void loginbutton_click(object sender, eventargs e) { sqlconnection conn = new sqlconnection(configurationmanager.connectionstrings["registrationsconnectionstring"].connectionstring); conn.open(); string checkuser = "select count(*) registrationdata username='" + usernamelogin.text + "' "; sqlcommand com = new sqlcommand(checkuser, conn); int temp = convert.toint32(com.executescalar().tostring()); conn.close(); if (temp == 1) { conn.open(); string checkpassword = "select password registrationdata username='" + usernamelogin.text + "' "; sqlcommand passcom = new sqlcommand(checkpassword, conn); string password = passcom.executescalar().tostring().replace(" ", ""); if (password == passwordlogin.text) { session["new"] = usernamelogin.text; response.redirect ("default.aspx"); } else response.write("password incorrect"); } else { response.write("user not exist"); } }
for clarity, web.config (just automatically generated code) is:
<?xml version="1.0"?> <configuration> <connectionstrings> <add name="mwd" connectionstring="data source=p425\sqlexpress;initial catalog=mwd;integrated security=sspi;" /> <add name="registrationsconnectionstring" connectionstring="data source=(localdb)\v11.0;attachdbfilename=|datadirectory|\registrations.mdf;integrated security=true" providername="system.data.sqlclient" /> </connectionstrings> <system.web> <compilation debug="true" targetframework="4.5.1" /> <httpruntime targetframework="4.5.1" /> </system.web> <appsettings> <add key="validationsettings:unobtrusivevalidationmode" value="none" /> </appsettings> </configuration>
what have in autentication mode on webconfig file?
try similar this:
<authentication mode="forms"> <forms name="test" loginurl="login.aspx" defaulturl="default.aspx" cookieless="usecookies" path="/"></forms> </authentication>
another way check if getting username using user.identity.name, can debug in code behind of master page.
Comments
Post a Comment