Virtual path isn't working in Response.Redirect

  • Thread starter Thread starter FN
  • Start date Start date
F

FN

I'm using User.Identity.IsAuthenticated on all my pages (from a base class),
and redirecting to a login page if not authenticated. The problem is that
some pages are in subfolders and others are not. Such as:

www.domain.com/mustbeauth1.aspx > www.domain.com/login.aspx

www.domain.com/folder/mustbeauth2.aspx > www.domain.com/login.aspx

If I use Response.Redirect("login.aspx") the first one works, but the second
doesn't. I thought I could then use Response.Redirect ("/login.aspx") but
that causes an exception. And I don't want to hard-code the whole domain
in case this site is used on different domains. So, how can I reference
the virtual path of a file at the root level?
 
FN said:
I'm using User.Identity.IsAuthenticated on all my pages (from a base class),
and redirecting to a login page if not authenticated. The problem is that
some pages are in subfolders and others are not. Such as:

www.domain.com/mustbeauth1.aspx > www.domain.com/login.aspx

www.domain.com/folder/mustbeauth2.aspx > www.domain.com/login.aspx

If I use Response.Redirect("login.aspx") the first one works, but the second
doesn't. I thought I could then use Response.Redirect ("/login.aspx") but
that causes an exception. And I don't want to hard-code the whole domain
in case this site is used on different domains. So, how can I reference
the virtual path of a file at the root level?
Using ~ in a .NET call to something like Response.Redirect means the
application's root level (.NET will map it for you). So do a

Response.Redirect("~/login.aspx")
 
Back
Top