Avoiding Global.asax for caching "VaryByCustom"

I am writing a custom HttpModule and I need to use:

 Response.Cache.SetVaryByCustom("role"); 

Basically, I need to cache responses based on the role of the user. All my research pointed me to the page:

http://msdn.microsoft.com/en-us/library/5ecf4420 (v = vs .100) .aspx

Where it is suggested to override GetVaryByCustomString in Global.asax.

Is there a way to avoid this in global.asax? Suppose I create a shrink wrapped application.

+4
source share
1 answer

Why does a compressed-layer application exclude Global.asax?

Try the following:

  public override string GetVaryByCustomString(HttpContext context, string custom) { if (custom == "role") return Roles.GetRolesForUser().Aggregate((a,b) => a = a+b); } 
0
source

Source: https://habr.com/ru/post/1441799/


All Articles