Solved

Forms Authentication & ReturnUrl

Posted on 2004-08-04
20
1,355 Views
Last Modified: 2008-01-16
Here's my problem, should be simple enough to understand

In development, my application is located here
http://localhost/myapp/mypage.aspx

But in production, it is deployed like so
http://mydomain.com/mypage.aspx <-- removing "myapp" from the url

But when I try to hit a page when I am not authenticated, I get bumped to the login page which looks like this:

http://mydomain.com?ReturnUrl=%2fmyapp%2fmypage.aspx, so after a successful login, they get a nice 404 error, because

http://mydomain.com/myapp/mypage.aspx doesn't exist

Any ideas on how I can instruct forms authentication to remove the "/myapp" from the returnurl?

--Michael
0
Comment
Question by:raterus
  • 7
  • 5
  • 3
  • +3
20 Comments
 
LVL 25

Expert Comment

by:nauman_ahmed
Comment Utility
http://mydomain.com?ReturnUrl=default.aspx. In default.aspx check to see if user is authenticated and redirect where is required.

Best, Nauman
0
 
LVL 28

Expert Comment

by:mmarinov
Comment Utility
Hi,
have you set in the production that your login page is not myapp/mypage.aspx but mypage.aspx ?

Regards,
B..M
0
 
LVL 33

Author Comment

by:raterus
Comment Utility
nauman, the problem is, it never gets to default.aspx to be checked (not that I would manually check this in each page if it was), it is adding the application name to the return url, so after logging in with the returnurl set, I get 404 errors.  I just want to remove the application name from the returnurl, that's it.

mmarinov, mypage.aspx is the secured page, not the login page.  I've ensured that my appname isn't in the loginurl in web.config though, it didn't seem to make a difference.
0
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
put the following code in your web.config file:

 <authentication mode="Forms">
            <forms name="appNameAuth" path="/" loginUrl="mypage.aspx" protection="All" timeout="30" />
         
        </authentication>
0
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
those lines will specify mypage.aspx as your login page and the exact path to the page will not be specified so when you move that web.config to another server it will use the path of that server
0
 
LVL 28

Assisted Solution

by:mmarinov
mmarinov earned 150 total points
Comment Utility
i see now
so to redirect to a page skiping the /myapp/ you have to redirect manuall by removing the %2fmyapp%2f from the ReturnUrl
Regards,
B..M
0
 
LVL 33

Author Comment

by:raterus
Comment Utility
YZlat, you are correct, that will get me directly to my login page, but that isn't he problem, the returnurl is showing the app name, which after I login in doesn't map correctly.

mmarinov, I certainly can remove /myapp from the returnurl, but I was hoping there would be some way to configure asp.net to forget about the appname so the returnurl would be correct.  If not, I'll just do it that way.
0
 
LVL 9

Expert Comment

by:crescendo
Comment Utility
Raterus:

I think this arises when you copy the project to the production server. If you use Copy Project in VS.Net and use FrontPage as the copy method it sorts itself out, but if you use fileshare, or use Xcopy, it retains the virtual directory name that you developed under.
0
 
LVL 33

Author Comment

by:raterus
Comment Utility
crescendo, so what difference would copy project via frontpage make to my server that I could do manually when using xcopy?
0
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
check this out and click on the link provided on that page. That problem is same as yours

http://www.wilsondotnet.com/Tips/ViewPosts.aspx?Thread=461

http://weblogs.asp.net/HernanDL/archive/2004/06/09/ssoformsauth.aspx
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 35

Expert Comment

by:YZlat
Comment Utility
your application is checking for a cookie attached to the Request and if it doesn't find it,
-redirect takes place and a ReturnURL appended to the querystring
0
 
LVL 9

Expert Comment

by:crescendo
Comment Utility
Raterus:

Have you, by any chance, created a virtual directory "myApp" and pointed it at the wwwroot folder?
0
 
LVL 33

Author Comment

by:raterus
Comment Utility
I looked at those articles, actually it was the second time today I had seen them.  I came across them earlier while trying to research this issue myself before posting this question.  They describe two separate applications using the same forms-authentication cookie.  While intriguing to realize you can do that, it isn't exactly what I'm doing here.
0
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
0
 
LVL 33

Author Comment

by:raterus
Comment Utility
crescendo, here is my setup, and you kind of made a light go off in my head as to why this isn't working.

IIS IS configured with this application set up how the returnurl specifies, it is in it's own directory configured as an application with "myApp".  

We don't keep IIS open directly to the world, so we have Apache running as a proxy server between IIS and the mean cruel world.  This basically translates incoming requests to "http://mydomain.com/mysite.aspx" to an internal address "http://safelybehindapache/myApp/mysite.aspx"

Well don't know what to say from here, I'm not really expecting to convince asp.net it isn't where it thinks it is at... :-)
0
 

Expert Comment

by:samdlg
Comment Utility
what about

path="~/myApp/mysite.aspx"

the tilde will redirect to the app folder.

0
 
LVL 33

Author Comment

by:raterus
Comment Utility
are you referring to the path property in web.config in the <forms> tag?.  That is referring to the path of the authentication cookie, not a specific page.
0
 

Expert Comment

by:samdlg
Comment Utility
why not try:

    <authentication mode="Forms" >
            <forms name="FirstPage" loginUrl="http://safelybehindapache/myApp/site_login.aspx" />
    </authentication>
0
 
LVL 9

Accepted Solution

by:
crescendo earned 350 total points
Comment Utility
See what you mean...

Assuming the server is Windows Server, and not Pro, how about setting up your app as a new web site rather than a virtual directory? Just call it xxx.thingy.zzz it doesn't have to be a real name. Then in the advanced properties for the site, tell it to look for that name in the header. Set the name and IP address in the Apache servers /etc/hosts file, and tell it to redirect to the new name. You should then have two root-based systems.
0
 
LVL 33

Author Comment

by:raterus
Comment Utility
last post by crescendo is what will work, though I'm not going to go that route when it is a simple one-line change to weed out the application name from the return url and redirect as mmarinov suggested.  Problem solved!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now