Trying to call a function from another file
I have a function in a class file called auth_user and its in App_code folder. I am trying to call that function from random pages that are on the website. Inside the class f开发者_Python百科ile is a function that is simple, basicly check for flags in the sessions, i just wanna have it there so i dont have to type it again and again. I want to be able to call it with one function like auth_user();
How would i do this excetly ? would the function be public static void or what ?
Static makes sense for this:
public class AuthUtility
{
public static bool IsUserAuthorized()
{
....
return retVal;
}
{
And then you would call it:
AuthUtility.IsUserAuthorized();
Edit Based on Comments
So, not to be rude, but that information in your comments would've been pertinent in your original question and saved a fair amount of time.
Regardless, you'll need to pass in either the current HTTPContext or the Current Session into your static method:
public class AuthUtility
{
public static void AuthorizeUser(HttpSessionState currentSession)
{
currentSession["whatev"] = "rockin";
.....
}
}
And the you would call it:
AuthUtility.AuthorizeUser(this.Session);
精彩评论