ورود

View Full Version : دسترسی به session , cache در کلاسها



bahman7210
دوشنبه 07 آذر 1390, 20:31 عصر
چه جوری میشه به session دسترسی پیدا کرده در کلاسهایی که Ui نیستند؟؟؟؟


public


class SecurityHttpModule : System.Web.UI.Page , IHttpModule

{



public SecurityHttpModule() { }



public void Init(HttpApplication context)

{

context.BeginRequest +=

new EventHandler(Application_BeginRequest);

}



private void Application_BeginRequest(object source, EventArgs e)

{



HttpContext context = ((HttpApplication)source).Context;



string ipAddress = context.Request.UserHostAddress;



if (IsValidIpAddress(ipAddress))

{



if (Cache["Groups"] != null)



//context.Response.StatusCode = 403; // (Forbidden)

context.Response.Redirect(

"http://yahoo.com",false);



}

}



private bool IsValidIpAddress(string ipAddress)

{



return true;



return (ipAddress == "127.0.0.1");

}



public void Dispose() { /* clean up */ }

}

PhoenixNet
دوشنبه 07 آذر 1390, 22:17 عصر
ابتدا System.Web را به پروژه خود اضافه نمایید.
سپس مانند خط زیر می توانید به کلاس های مربوط به وب دسترسی داشته باشید.

int i= System.Web.HttpContext.Current.Cache.Count;