隐藏母版页内容页面中的一些内容ASP.NET C# [英] Hide master page some content in content pages ASP.NET C#

查看:48
本文介绍了隐藏母版页内容页面中的一些内容ASP.NET C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了web应用程序,其中

1-我想隐藏一些母版页内容(链接到其他页面(菜单),按钮)



2-我想限制登录用户和未登录用户的某些页面访问权限。



i有5页viz主页,注册,事务,view_transactions,仪表板



i shld限制访问页面事务,view_transactions,仪表板到非登录用户。



如何在c#asp.net中实现这个目标。





我的主页代码:



I created web application, in that
1- i want hide some master page contents(ex- links to other pages(Menu), buttons)

2- i want to restrict the some page access for logged in users and non logged in users.

i have 5 pages viz homepage,register,transactions,view_transactions,dashboard

i shld restrict accessing the pages transactions,view_transactions,dashboard to non logged in users.

how to achieve this in c# asp.net.


My master page code:

 <pre><%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Expense.master.cs" Inherits="Expense_System.Expense" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <link href="App_Themes/Theme1/MasterPageStyle.css" rel="stylesheet" />

    <title> Expense System</title>
    <asp:ContentPlaceHolder ID="head" runat="server">
        
             

    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">

    <div>
      
            <asp:Menu ID="Menu1" runat="server" BackColor="#FFFBD6" DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#990000" Orientation="Horizontal" RenderingMode="Table" StaticSubMenuIndent="10px" style="font-weight: 700; color: #FFFFFF; background-color: #99CCFF; font-size: xx-large; text-align: center;" Width="99%" Height="67px">
                <DynamicHoverStyle BackColor="#990000" ForeColor="White" />
                <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
                <DynamicMenuStyle BackColor="#FFFBD6" />
                <DynamicSelectedStyle BackColor="#FFCC66" />
                <Items>
                    <asp:MenuItem NavigateUrl="~/HomePage.aspx" Text="Home Page" Value="Home Page"></asp:MenuItem>
                    <asp:MenuItem NavigateUrl="~/Register.aspx" Text="Register" Value="Register"></asp:MenuItem>
                    <asp:MenuItem NavigateUrl="~/Loginpage.aspx" Text="Login" Value="Login"></asp:MenuItem>
                </Items>
                <StaticHoverStyle BackColor="#990000" ForeColor="White" />
                <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
                <StaticSelectedStyle BackColor="#FFCC66" />
            </asp:Menu>
  
    

        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
  
          
  
          
  
        </asp:ContentPlaceHolder>
          

    </div>
    </form>
</body>
</html>










<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;


namespace Expense_System
{
    public partial class Loginpage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }


        protected void btnlogin_Click(object sender, EventArgs e)
        {

            String strConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;

            SqlConnection con = new SqlConnection(strConnString);

            SqlCommand cmd = new SqlCommand("SELECT * FROM User_details WHERE [Login Id]=@loginid AND [Password]=@password",con );
            cmd.Parameters.Add("@loginid", SqlDbType.VarChar).Value = loginid.Text;
            cmd.Parameters.Add("@password", SqlDbType.VarChar).Value = pwd.Text;

            //cmd.CommandType = CommandType.StoredProcedure;

            //con.Open();

            //cmd.CommandText = "SPchkloginuser";

            //cmd.Parameters.Add("@loginid", SqlDbType.VarChar).Value = loginid.Text;
            //cmd.Parameters.Add("@password", SqlDbType.VarChar).Value = pwd.Text;
            //cmd.Connection = con;


            //SqlDataAdapter da = new SqlDataAdapter(cmd.CommandText,con);

            SqlDataAdapter da = new SqlDataAdapter(cmd);

            DataTable dt = new DataTable();
            da.Fill(dt);
            if(dt.Rows.Count > 0)
            {

                Response.Redirect("Transactions.aspx");
               
            }

            else
            {
                
                Response.Write("<script>alert('Invalid credentials')</script> ");
               
            }
        }
    }
}





我尝试了什么:



我没有逻辑,我是编码和语言的新手



What I have tried:

I am not getting logic, i'm new to coding and language also

推荐答案

如果您是ASP.NET的新手并希望实现页面访问安全性,我建议您开始查看:演练:管理带角色的网站用户 [ ^ ]
If you are new to ASP.NET and wanted to implement page access security, I'd suggest you to start looking at: Walkthrough: Managing Web Site Users with Roles[^]


如果您不想进入通用的东西,可以使用Master.FindControl来访问母版页的控件。您的内容页面......
If you do not want to get into something generic, you can access controls of the master page using Master.FindControl from your content page...


这篇关于隐藏母版页内容页面中的一些内容ASP.NET C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆