简体   繁体   English

(C#-ASP.NET-REDIRECT-LOGIN)如何在重定向页面之前获取URL? 登录方式

[英](C#-ASP.NET-REDIRECT-LOGIN) how to get the url before redirecting the page? In login method

how to get the url before redirecting the page? 重定向页面前如何获取网址?

Example: in A.aspx page has a link that redirects to page b.aspx, and that in "pageload" on page b.aspx I need to grab the link from the previous page: A.aspx. 示例:在A.aspx中,页面具有重定向到页面b.aspx的链接,而在b.aspx页面中的“页面加载”中,我需要从上一页:A.aspx中获取链接。

The scenario is: 该方案是:

When the timeout expires I need to redirect the user to the login page again, but I need save the url that it was accessing, because when he login again I need redirect it to the same page 超时到期后,我需要再次将用户重定向到登录页面,但是我需要保存它正在访问的URL,因为当他再次登录时,我需要将其重定向到同一页面

(C#-ASP.NET-REDIRECT-LOGIN) how to get the url before redirecting the page? (C#-ASP.NET-REDIRECT-LOGIN)如何在重定向页面之前获取URL? In login method 登录方式

Ty.

Edit 编辑

***if (Page.Request.RawUrl != null && !Page.Request.RawUrl.ToUpper().Equals("/DEFAULT.ASPX"))
   {
     cookie.Value = Page.Request.RawUrl.ToString();
     cookie.Expires = DateTime.Now.AddSeconds(SessionLengthMinutes * 2);
     Response.Cookies.Add(cookie);
   }***

I use this! 我用这个!

Save the link in a session object and then redirect the user. 将链接保存在会话对象中,然后重定向用户。 On successful login retreive the value form session object. 成功登录后,检索值表单会话对象。

Session["PathBeingAccessed"] = "www.xyz.com"; Session [“ PathBeingAccessed”] =“ www.xyz.com”;

if (Page.Request.UrlReferrer != null)
            {
           Response.Redirect(Page.Request.UrlReferrer.ToString(),false);
            }

On Login: 登录时:

if(Session["PathBeingAccessed"]!=null)
{
Response.Redirect(Session["PathBeingAccessed"].toString();)
}

Be carrefull it's a big security issue if the UrlReferrer is not on same web site; 要小心,如果UrlReferrer不在同一网站上,这将是一个很大的安全问题。 I think you need to check url before (domain or whaterver else) 我认为您需要先检查url(域或其他)

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

相关问题 重定向到登录页面时,如何使ASP.NET身份验证保留Url片段? - How to make ASP.NET authentication persist the Url Fragment when redirecting to the login page? ASP.NET 核心重定向到登录页面而不返回 url - ASP.NET Core redirect to login page without return url asp.net重定向到登录页面 - asp.net redirecting to login page 如果用户使用ASP.NET直接在浏览器中输入URL,如何重定向到登录页面 - how to redirect to login page if user directly entres URL in browser using ASP.NET 如何根据用户在Asp.net C#中的角色将用户从登录页面重定向到下一页 - how to redirect user from login page to next page base on their Role in Asp.net C# 如何从ASP NET Core中的AuthorizationFilter重定向到登录页面? - How to redirect to login page from AuthorizationFilter in asp net core? 登录页面未重定向到iis服务器asp.net C#中的主页 - login page not redirecting to main page in iis server asp.net c# ASP.NET C#登录重定向 - ASP.NET C# Login Redirect ASP.NET将某些页面重定向到登录页面 - ASP.NET redirecting certain pages to login page 如何在 .ASP.NET Core MVC 中使用多个登录页面和未经授权的用户重定向不同的登录页面 - How to use multiple login pages in .ASP.NET Core MVC and unauthorized user redirect different login page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM