简体   繁体   English

如何在asp.net FriendlyUrls中使用ReturnUrl?

[英]How to use ReturnUrl in asp.net FriendlyUrls?

I am beginner to FriendlyUrl concept in asp.net. 我是asp.net中的FriendlyUrl概念的初学者。 I want use ReturnUrl for login page. 我想使用ReturnUrl作为登录页面。 Can still use http://localhost:8080/login?ReturnUrl=/page ? 仍然可以使用http://localhost:8080/login?ReturnUrl=/page吗?

So once user logins in will be redirected to returnurl 因此,一旦用户登录,系统将重定向到returnurl

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. 您的ReturnUrl是Querystring 参数 ,Friendlyurls插件将保持不变,但是Friendlyurl不会单独使用此参数进行重定向。 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. 您在代码中唯一需要做的就是在登录代码完成并成功验证用户身份之后,使用此参数执行Response.Redirect you can leave the slash out so it gets easier. 您可以省略斜线,这样会更容易。 Just do this in your code behind: 只需在后面的代码中执行此操作即可:

VB VB

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

C# 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. 这样,您的代码将检查ReturnUrl是否可用,如果可用,请使用它进行重定向,或者使用默认重定向(如果可用)。

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 . 如果要重定向到的页面在项目的子文件夹中,则需要将子文件夹添加到重定向位置,如下所示: ReturnUrl=SubfolderName/Page This is always important, even when you are using FriendlyUrls and Distinct page names. 即使您使用的是FriendlyUrls和Distinct页面名称,这始终很重要。

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. 我有一个同样的问题,其中FriendlyUrls不能作为ReturnUrl使用,我使用的解决方案是覆盖如下所示的ReturnUrl。 An extra option would be with Jeroens code to use the ReturnUrl. Jeroens代码将提供一个额外的选项来使用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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM