Every stored procedure we write has to have clientip, serverip, windows username, etc passed on to it.
The question is how do I efficiently pass these to DAL?
Every stored procedure we write has to have clientip, serverip, windows username, etc passed on to it.
The question is how do I efficiently pass these to DAL?
You should have all of the above data accessible either in the System.Environment class, or in your own Thread Principal of some kind. Your DAL can easily pull in from both or either of those sources.
Create a class to hold this data, a factory to build it and helper methods to consume it.
IUserContext
{
int param1 {get;set;}
int param2 {get;set;}
SqlParameter[] GetSqlParameters();
}
UserContext : IUserContext{}
UserContextFactory
{
internal IUserContext IUserContextFromRequest(){}
}
Good luck
I'm assuming this is a web app in ASP.NET. If that's the case, you have access to all these things in the context of a web request outside of the web application through the following static instance:
System.Web.HttpContext.Current
If everything you need is standard stuff that you usually have in the Request, Response, and User objects that are available by default at the Page level, then this should be all you need. If you need information that is custom to your web app, then Ben's answer (above) should work.