我写了一个类用来判断Session 然后其他页面继承PageBase 
在PageBase中 如果发现Session 没有值,则让起重定向到login.aspx public partial class PageBase : System.Web.UI.Page
{
    string _sUnitCode = null;    public string sUnitCode
    {
        get
        {
            return _sUnitCode;
        }
    }    static void Page_Load(object sender, EventArgs e)
    {    }
    protected override void OnInit(EventArgs e)
    {
        if (Session["sUnitCode"] == null)
        {
            string aaa = UrlBase;
              // MessageBox.ShowRedirect(this, "请先登录","login.aspx");            Response.Redirect("login.aspx");
             如果跟login.aspx不在一个目录下 则转不到该页面,我一说 相信大家都知道 
               这个地方该如何处理,请高手指教
         //   Response.Redirect
        }
        else
        {
            _sUnitCode = Session["sUnitCode"].ToString();
        }
    }
}

解决方案 »

  1.   

    然道login.aspx没有公共目录?如果没有就建立个公共目录
      

  2.   

    公共目录?
      不是很明白, 我现在是有几个页面跟login.aspx  放在根目录的,业务方面的页面放在根目录下的新建文件里面
      

  3.   

     Response.Redirect("/login.aspx"); 
      

  4.   

     Response.Redirect("login.aspx"); 
     
     页面的跳转写绝对路径,通过公共变量来控制页面的URL。(比如写在web.config画面也可以)
      

  5.   

    用绝对路径来定位
    如: 
    Response.Redirect("/login.aspx");
      

  6.   

    Response.Redirect(Page.ResolveUrl("login.aspx")); 
    试试看
      

  7.   

    public static string GetBaseURL()
        {
            if (HttpContext.Current.Request.ApplicationPath == "/")
            {
                return @"http://" + HttpContext.Current.Request.Url.Host;
            }
            else
            {
                return @"http://" + HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.ApplicationPath;
            }
        } Response.Redirect(GetBaseUrl+"/login.aspx");
      

  8.   

    用一个“../”上跳一层,上跳两层则用两个,即“../../”,跟Dos下访问本地目录一个道理。
    例如,跳转前的页面是“wwwroot/manage/current/current.aspx”,而login.aspx在“wwwroot/common/login.aspx”,则从current.aspx转到login.aspx应该写成:
    Response.Redirect("../../common/login.aspx");
      

  9.   

    Response.Redirect("~/login.aspx");这个是最好的
      

  10.   

    取决对路径 :如 Response.Redirect("~/login.aspx");
      

  11.   


    //这个是获取网站根目录
    Response.Redirect("~/");
    //如果就在根目录下
    Response.Redirect("~/login.aspx");
    //或者子目录下面就
    Response.Redirect("~/../../login.aspx");
      

  12.   

    Response.Redirect(Server.MapPath("login.aspx")); 
      

  13.   

    用绝对路径来定位 
    如: 
    Response.Redirect("/login.aspx");
      

  14.   


    Response.Redirect("~/login.aspx");
      

  15.   

    如果你的login.aspx页面是在网站根目录下这样就可以了
    Response.Redirect("~/login.aspx");