473,396 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 4430
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: FN | last post by:
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...
2
by: Dune | last post by:
I'm trying to execute an aspx page by calling Server.Execute. The aspx page I'm trying to execute is in a different web app from the aspx page containing the Server.Execute statement. A slightly...
2
by: Tom Wells | last post by:
I have a little file upload page that I have been able to use to successfully upload files to the C: drive of LocalHost (my machine). I need to be able to upload to a network drive from the intranet...
3
by: mark.irwin | last post by:
Hello all, Have an issue where a redirect pushes data to a page with a select case which then redirects to another page. Problem is the redirect isnt working in 1 case. Code below: strURL =...
5
by: Stu Carter | last post by:
Hi, ENV: Windows 2003 Server SP1 (+all updates), VS 2003, .Net 1.1 SP1 We've got an ASP.Net web application using State Service. All is fine until we tried to use the app through a virtual...
5
by: mbosco51 | last post by:
Hi. I have a virtual path setup in order to give my web server access to a file on my app server. I am using the file system object to check for the existance of the file and if it exists, it has...
1
by: Webmills | last post by:
Has anyone come across the problem that I am experiencing? I have a master page using four or five Hyperlink controls, each with an ImageUrl. The ImageUrl is specified using a virtual directory...
4
by: tommaso.gastaldi | last post by:
Hi friends I was in the need to find a sort of "definitive" :) solution to transform a virtual path such as "~/MyDir/MyFile into a full web address. In particular I needed it * within web...
3
by: Athmaus | last post by:
Hello, I have this ecom page that i am making where customers can select to choose additional licenses before they purchase. I have that part working with javascript. Problem is that when the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.