App_Code

Tom Knowlton
Tom Knowlton used Ask the Experts™
on
I created an App_Code directory.
I created a class file.

But I cannot figure-out how to reference it elsewhere in my codebehind.

I try getting to it via the namespace but GlobalMethods does not show up.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Campus_Webstore.App_Code
{
    public static class GlobalMethods
    {

        public static void ManualRedirectToPage(string pagetogoto)
        {
            string usehttps = System.Configuration.ConfigurationManager.AppSettings["USEHTTPS"] as string;
            string serverName = HttpUtility.UrlEncode(Request.ServerVariables["SERVER_NAME"]);
            string serverPort = HttpUtility.UrlEncode(Request.ServerVariables["SERVER_PORT"]);
            string vdirName = Request.ApplicationPath;
            if (usehttps == "YES")
            {
                Response.Redirect("https://" + serverName + ":" + serverPort + "/" + pagetogoto);
            }
            else
            {
                Response.Redirect("http://" + serverName + ":" + serverPort + "/" + pagetogoto);
            }
        }
    }
}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
you have to first refernce the namespace. if GlobalMethod is not in the same namespace as the .cs file where you are using it. you cant access it.

first add the namespace to your file:
using Campus_Webstore.App_Code;

now you should be able to use GlobalMethod

 
Commented:
right click the class file in the solution explorer window, select properties and choose the compile value for the build action property.  Also make sure you have the using statement correct.

hope this helps
Tom KnowltonWeb developer

Author

Commented:
thx

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial