One: intercepts all HTTP requests to the server.
Add in config,
<system.webserver><modules><add name="httpauthvalid " type= " ygpt. Country.Auth.HttpAuthvalid"/></modules></system.webserver>
Then each HTTP request is advanced by this class (this class needs to inherit
System.Web.IHttpModule
)
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingsystem.web;usingNewtonsoft.json;namespaceygpt. country.auth{/// <summary> ///Permission Validation/// </summary> Public classHttpAuthvalid:System.Web.IHttpModule { Public voidDispose () {//Place the purge code here. } Public voidInit (HttpApplication context) {context. AcquireRequestState+=NewEventHandler (systemprocess); } /// <summary> ///system access processing (System resource loading, permission validation, etc.)/// </summary> voidSystemprocess (Objectsender, EventArgs e) {HttpApplication application= (HttpApplication) sender;//Get Application stringurl = Application. Request.Url.AbsolutePath.ToString ();//Get URL if(url = ="/settoken")//If the token is set { if(!string. IsNullOrEmpty (Application. context.request["param"]) {HttpCookie cookie= Application. request.cookies["Ygpt_sessionid"]; if(Cookie = =NULL) {Cookie=NewHttpCookie ("Ygpt_sessionid"); } //Combine reset cookie tokensCookies. Value =application. context.request["param"] +ygpt. Country.Auth.EncryptDecrypt.AESEncrypt (ygpt. Country.Auth.Config.DesToValue+ DateTime.Now.ToString ("YYYYMMDD"), Config.decryptkey); Cookies. HttpOnly=true; Cookies. Expires= DateTime.Now.AddDays ( -); Application. Response.appendcookie (cookie); Application. Response.Write ("Jsonphandler ({\ "result\": \ "1\"})");//Successapplication. Response.End (); return; } Else{application. Response.Write ("Jsonphandler ({\ "result\": \ "0\"})");//failedapplication. Response.End (); return; } } if(Application. request.cookies["Ygpt_sessionid"] ==NULL||string. IsNullOrEmpty (Application. request.cookies["Ygpt_sessionid"]. Value) {application. Response.Redirect (ygpt. COUNTRY.AUTH.CONFIG.TIMEOUTURL);//Jump to timeout pageapplication. Response.End (); return; } //string permisweburl = system.configuration.configurationmanager.appsettings["Permisweburl"]; //string[] Pweburls = Permisweburl.split (', '); //for (int i = 0; i < Pweburls. Length; i++)//{ //if (URL. Contains (Pweburls[i]))//Login Timeout No permissions do not authenticate// { //return; // } //} if(system.configuration.configurationmanager.appsettings["Workingmode"] !="Deve") { if(URL.) IndexOf (". aspx") >=0)//Page Permissions{User MyUser=Currentuser.getuser (); if(MyUser. Userid.toupper () = ="ADMIN") { return; } /*Verify page Permissions*/ygpt. Country.Auth.SystypeValue SV=NewSystypevalue (); Sv. Systype=Config.systemtype; Sv. ValueName=URL; if(MyUser. PageHandButton.PageCollect.Contains (SV)) {///Skip to the No Permissions pagecurrentuser.goto_nopermission (); } } Else if(URL.) IndexOf (". ashx") >=0)//HTTP Request Permission{User MyUser=Currentuser.getuser (); Application. Response.ContentType="Text/plain"; Application. Response.Buffer=true; Application. Response.ExpiresAbsolute= DateTime.Now.AddDays (-1); Application. Response.AddHeader ("pragma","No-cache"); Application. Response.AddHeader ("Cache-control",""); Application. Response.CacheControl="No-cache"; if(CurrentUser.Userid.ToUpper () = ="ADMIN") { return; } //Verify Request Permission ////Data processing must contain req parameters if(string. IsNullOrEmpty (Application. context.request["req"])) { ///Skip to the No Permissions pageApplication. Response.Write (Jsonconvert.serializeobject ("nopermission")); Application. Response.End (); } stringUrlandqu = URL +"? req="+ Application. context.request["req"]; Ygpt. Country.Auth.SystypeValue SV=NewSystypevalue (); Sv. Systype=Config.systemtype; Sv. ValueName=Urlandqu; if(MyUser. PageHandButton.PageCollect.Contains (SV)) {///returns no permission informationApplication. Response.Write (Jsonconvert.serializeobject ("nopermission")); Application. Response.End (); return; } } } } Public voidonlogrequest (Object source, EventArgs e) {//You can place custom logging logic here } }}
Intercept all HTTP requests to the server