0

I am beginner to FriendlyUrl concept in asp.net. I want use ReturnUrl for login page. Can still use http://localhost:8080/login?ReturnUrl=/page?

So once user logins in will be redirected to returnurl

James123
  • 11,184
  • 66
  • 189
  • 343

2 Answers2

3

Yes this is still possible but probably not what you are expecting if i understand your question correctly. Your ReturnUrl is a Querystring parameter which the Friendlyurls plugin will leave intact, but Friendlyurl does not use this parameter on its own to do a redirect. That's something you will have to do.

The only thing you need to do in code is use this parameter to do a Response.Redirect with after your login code has completed and succesfully authenticated your user. you can leave the slash out so it gets easier. Just do this in your code behind:

VB

If Request.QueryString("ReturnUrl") <> Nothing Then  
  Response.Redirect(Request.QueryString("ReturnUrl"))
Else
// Do your normal redirect here
End If

C#

if (Request.QueryString["ReturnUrl"] != "" && 
Request.QueryString["ReturnUrl"] != null) 
{  
    Response.Redirect(Request.QueryString["ReturnUrl"]);
}
else
{
    // Do your normal redirect here
}

This way your Code will check if the ReturnUrl is available and if so use it to do a redirect, or use your default redirect if available.

Of course you have to think of your folder structure of your project when redirecting; if your page to redirect to is in a sub folder in your project, the subfolder needs to be added to the redirect location like this: ReturnUrl=SubfolderName/Page. This is always important, even when you are using FriendlyUrls and Distinct page names.

Jeroen
  • 343
  • 1
  • 2
  • 12
  • was it not the awnser you are looking for James123? maybe i can help you further? – Jeroen Apr 29 '14 at 12:47
  • I have the same problem, only where in the code behind file should this be placed? – Cerveser Oct 16 '14 at 14:22
  • @Cerveser: Right after you have confirmed a succesfull account login and have created/prepared everything your application needs (example: Session variables containing account information and such). – Jeroen Oct 16 '14 at 15:42
0

I had the same problem where the FriendlyUrls where not working as an ReturnUrl, the solution I've used is overriding the ReturnUrl like below. An extra option would be with Jeroens code to use the ReturnUrl.

Protected Sub Login1_LoggedIn(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login1.LoggedIn
    'overrides ReturnUrl page parameter
    Response.Redirect(Login1.DestinationPageUrl)
End Sub
Cerveser
  • 752
  • 8
  • 23