protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (!AuthHelper.CheckAuth()) { Response.Redirect("~/Login.aspx"); } hdUserID.Value = AuthHelper.UserID; hdUserType.Value = AuthHelper.UserType; } GetQueryString(); if (!IsPostBack) { //BindData(strID); if (strType == "VIEW") { ViewMode(); } else if (strType == "EDIT") { EditMode(); } else { NewMode(); } BindData(strID); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (!AuthHelper.CheckAuth()) { Response.Redirect("~/Login.aspx"); } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (!AuthHelper.CheckAuth()) { Response.Redirect("~/Login.aspx"); } hdUserID.Value = AuthHelper.UserID; hdUserType.Value = AuthHelper.UserType; SetAccess(); } }
public void OnAuthorization(AuthorizationFilterContext context) { var accountService = context.HttpContext.RequestServices.GetService(typeof(IAccountService)) as IAccountService; var authInfoProvider = context.HttpContext.RequestServices.GetService(typeof(IAuthInfoProvider)) as IAuthInfoProvider; var token = context.HttpContext.Request.Query["token"]; try { var(checkResult, auth) = AuthHelper.CheckAuth(accountService, token, _needAuthorize, ActionTool.GetUid(context.ActionDescriptor), _roleNameList); switch (checkResult) { case CheckResult.Success: authInfoProvider.SetCurrent(auth); return; case CheckResult.AuthenticationFailed: context.Result = new ContentResult { StatusCode = 401, Content = "身份验证失败" }; break; case CheckResult.AuthorizationFailed: context.Result = new ContentResult { StatusCode = 403, Content = "没有授权" }; break; default: context.Result = new ContentResult { StatusCode = 401, Content = "身份验证失败" }; break; } } catch (Exception ex) { context.Result = new ContentResult { StatusCode = 401, Content = ex.ToString() }; } }
public async Task Invoke(HttpContext context) { var accountService = context.RequestServices.GetService(typeof(IAccountService)) as IAccountService; var authInfoProvider = context.RequestServices.GetService(typeof(IAuthInfoProvider)) as IAuthInfoProvider; var webSocketHandler = context.RequestServices.GetService(typeof(IMessagingWebSocketHandler)) as IMessagingWebSocketHandler; var(checkResult, auth) = AuthHelper.CheckAuth(accountService, context.Request.Query["token"], false, null, null); switch (checkResult) { case CheckResult.Success: authInfoProvider.SetCurrent(auth); break; case CheckResult.AuthenticationFailed: context.Response.StatusCode = 401; await context.Response.WriteAsync("身份验证失败"); break; case CheckResult.AuthorizationFailed: context.Response.StatusCode = 403; await context.Response.WriteAsync($"{auth?.User?.Account}未授权"); break; default: context.Response.StatusCode = 401; await context.Response.WriteAsync("身份验证失败"); break; } if (!context.WebSockets.IsWebSocketRequest) { return; } var client = new Client { UserId = auth.User.Id, ClientType = auth.ClientType.ToString() }; var socket = await context.WebSockets.AcceptWebSocketAsync(); await webSocketHandler.Link(client, socket); }