User-2004582644 posted
Hi there,
I have a created a project in Visual Studio 2017 using the
MasterPage.
I have added in MasterPage the method sLogins() for user authentication.
Now I need use this method in new Web Form with MasterPage.
I have tried this without success because the method sLogins() is not available from
MasterPage :
Mp.sLogins
Is not sufficient the public declaration of the method sLogins() to recall it in
new Web Form with MasterPage ?
Do anyone have an idea why?
My code below.
public void sLogins()
{
string username = Page.User.Identity.Name.ToLower();
string[] strusername = username.Split('\\');
if (strusername.Length > 0)
{
username = strusername[strusername.Length - 1];
string sql = @String.Format(" SELECT * FROM ");
sql += String.Format(" logins ");
sql += String.Format(" WHERE ");
sql += String.Format(" UPPER(username) IN (?); ");
using (OdbcConnection myConnectionString =
new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnMySQLA"].ConnectionString))
{
using (OdbcCommand command =
new OdbcCommand(sql, myConnectionString))
{
try
{
if (username != null)
{
command.Parameters.AddWithValue("param1", username.ToString().ToUpper());
command.Connection.Open();
using (OdbcDataReader reader = command.ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
....
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Msg", "alert('....');window.location='...';", true);
}
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Msg", "alert('....');window.location='...';", true);
}
}
catch (Exception ex)
{
throw new ApplicationException("operation failed!", ex);
}
finally
{
command.Connection.Close();
}
}
}
}
}
New Web Form with MasterPage
<%@ Page Title="" Language="C#" MasterPageFile="Mp.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ MasterType VirtualPath="Mp.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">