basepage

/// <summary>
/// Class1 の概要の説明です
/// </summary>
public class BasePage : System.Web.UI.Page
{
    protected string allUserCanAccess = null;
    //<summary>
    //OnInitのOverrides
    //</summary>
    //<param name="e"></param>
    //<remarks></remarks>
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        if (allUserCanAccess == null)
        {
            //load from config file
            //allUserCanAccess = ???????
        }

        if (!checkUser())
        {
            return;
        }
    }

    //<summary>
    //OnLoadのOverrides
    //</summary>
    //<param name="e"></param>
    //<remarks></remarks>
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        if (!checkUser())
        {
            return;
        }
    }

    protected void CommonRedirect(string url, bool endProcess)
    {
        Response.Redirect(url, endProcess);
    }

    private bool checkUser()
    {
        // this porperty is same as class name
        // we can adapt the class if they have the same prefix
        // string strPageName = this.GetType().BaseType.Name.Substring(0, 4); <---???????
        string strPageName = this.GetType().BaseType.Name;

        if (allUserCanAccess != null && allUserCanAccess.Contains(strPageName))
        {
            return true;
        }

        UserData userData = (UserData)this.Session["USER"];
        if (userData == null)
        {
            //Load from config file
            CommonRedirect("???", true);
            return false;
        }

        if (userData.AllowAccess == null)
        {
            return false;
        }

        if (userData.AllowAccess.Contains(strPageName))
        {
            return false;
        }

        return true;
    }

    protected bool DownFile(string fileName, byte[] fileData)
    {
        try
        {
            Response.Clear();
            Response.ClearHeaders();
            Response.Buffer = false;
           
            long fileLength = fileData.Length;
            Response.ContentType = "application/octet-stream";
            Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
            Response.AppendHeader("Content-Length", fileLength.ToString());

            Response.BinaryWrite(fileData);

            Response.Flush();
            Response.End();
        }
        catch
        {
            return false;
        }
        finally
        {
        }
        return true;
    }
}

 

public class UserData
{
 public UserData()
 {
        //
  // TODO: コンストラクタ ロジックをここに追加します
  //
      
 }
    private string userId = null;
    public string UserId {
        get{
           return userId;
        }
        set{
            userId = value;
        }
    }

    private List<string> allowList = null;
    public List<string> AllowAccess
    {
        get
        {
            return allowList;
        }
        set
        {
            allowList = value;
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值