469,890 Members | 1,416 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,890 developers. It's quick & easy.

Virtual path isn't working in Response.Redirect

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?
Nov 17 '05 #1
2 3474
FN wrote:
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")

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 17 '05 #2
FN wrote:
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")

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Dune | last post: by
2 posts views Thread by Tom Wells | last post: by
3 posts views Thread by mark.irwin | last post: by
5 posts views Thread by Stu Carter | last post: by
1 post views Thread by Webmills | last post: by
4 posts views Thread by tommaso.gastaldi | last post: by
3 posts views Thread by Athmaus | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.