Virtual path isn't working in Response.Redirect

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?
 
C

Craig Deelsnyder

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")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top