/// <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;
}
}
}