ASP.NET RETURNURL具体的搜索结果页面 [英] ASP.NET ReturnURL to specific search results page

查看:272
本文介绍了ASP.NET RETURNURL具体的搜索结果页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.net网站与C#后端code。我们在它下面(有删节)code,这符合我们的需要,但它可能会更好。这是一种称为SearchResults.aspx页面上。如果用户没有登录,则链接将其重定向到登录页面。如果他们登录,它会重定向到该项目的查询页面。我希望它做的是将其重定向到相应的网页,他们在登录后,如果他们点击链接中不记录了。以何种方式,我需要的RETURNURL供应到登录页面?我已经尝试了各种方式,它只是重定向我的默认页面登录后。

 < AnonymousTemplate>
    <! - 要换下面的链接,以便返回URL会带我去
    ItemInformation.aspx - >
     <%#DataBinder.Eval的(的Container.DataItem,itemnumber)的ToString()修剪()%方式>< BR />
     < ASP:超链接=服务器ID =HyperLink1NavigateUrl ='账户/的Login.aspx'>
     请登陆后查看该项目的信息< / ASP:超链接>
< / AnonymousTemplate>
<&显示LoggedInTemplate GT;
    < ASP:超链接ID =HyperLink1=服务器NavigateUrl ='<%#
       〜/ ItemInformation.aspx&放大器;项目编号=+的DataBinder.Eval(的Container.DataItem,
       。itemnumber)的ToString()修剪()+&放大器; itemdept =+的DataBinder.Eval(
       的Container.DataItem,部)的ToString()%方式>'
       文字='<%#DataBinder.Eval的(的Container.DataItem,itemnumber)%>'>
    < / ASP:超链接>
< /&显示LoggedInTemplate GT;

修改 - 我使用一个ASP.net Web应用程序模板默认的登录结构,所以这是所有在登录后端

 保护无效的Page_Load(对象发件人,EventArgs的发送)
    {
        字符串RETURNURL =的Request.QueryString [RETURNURL];
        RegisterHyperLink.NavigateUrl =Register.aspx?RETURNURL =+
          HttpUtility.UrlEn code(的Request.QueryString [RETURNURL]);
    }


解决方案

在我的尝试之一,试图得到它的工作,我只是在尝试将DestinationPageUrl属性为我的asp:登录控件。出于某种原因,它要求我同时使用这和OnLoggedIn的盛会联系在一起(我不知道这个事件的存在之前Zerkey指出来)。在返回URL的附加问号也引起问题,所以这里就是我在做的Login.aspx

标记:

 < ASP:登录ID =LoginUserRUNAT =服务器的EnableViewState =假
       RenderOuterTable =假OnLoggedIN =UserLoginOnLoggedIn> ...< / ASP:登录>

code:

 保护无效UserLoginOnLoggedIn(对象发件人,EventArgs的发送)
    {
        字符串为itemid,itemdept;
        尝试
        {
            S1 =的Request.QueryString [项目编号] TRIM()。
            S2 =的Request.QueryString [部门] TRIM()。
        }
        抓住
        {
            //使字符串空,如果查询字符串不是present
            S1 =;
            S2 =;
        }
        字符串RETURNURL =的Request.QueryString [RETURNURL] +&放大器;项目编号=+
            的Request.QueryString [项目编号] +&放大器;部=+
                        的Request.QueryString [部门];
        如果((String.IsNullOrEmpty(RETURNURL)及!&放大器;!String.IsNullOrEmpty(S1)及&放大器;
        !String.IsNullOrEmpty(S2)))
            LoginUser.DestinationPageUrl = RETURNURL;
        其他
            LoginUser.DestinationPageUrl =〜/ Default.aspx的;
        的Response.Redirect(LoginUser.DestinationPageUrl);
    }

I have an ASP.net site with C# backend code. We have the following (abridged) code in it, which suits our needs, but it could be better. This is on a page called SearchResults.aspx. If the user is not logged in, the links will redirect them to the login page. If they are logged in, it will redirect them to a lookup page for that item. What I want it to do is to redirect them to the corresponding item page after they log in if they click the "not logged in link". In what way would I need to supply the returnURL to the login page? Every way I've tried, it just redirects me to the default page after login.

<AnonymousTemplate>
    <!--Want to change the link below so that the return URL will take me to 
    ItemInformation.aspx-->
     <%# DataBinder.Eval(Container.DataItem, "itemnumber").ToString().Trim() %><br/>
     <asp:HyperLink runat="server" ID="HyperLink1" NavigateUrl='Account/Login.aspx'>
     Please login to review information for this item.</asp:HyperLink>
</AnonymousTemplate>
<LoggedInTemplate>
    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#
       "~/ItemInformation.aspx?&ItemID=" + DataBinder.Eval(Container.DataItem,
       "itemnumber").ToString().Trim() + "&itemdept=" + DataBinder.Eval(
       Container.DataItem, "department").ToString()%>'
       Text='<%# DataBinder.Eval(Container.DataItem, "itemnumber")%>'>
    </asp:HyperLink>
</LoggedInTemplate>

Edit - I'm using the default login structure for an ASP.net Web Application template, so this is all that is in the Login backend.

    protected void Page_Load(object sender, EventArgs e)
    {
        string returnUrl = Request.QueryString["ReturnUrl"];
        RegisterHyperLink.NavigateUrl = "Register.aspx?ReturnUrl=" +
          HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
    }

解决方案

In one of my attempts to try to get it to work, I was only attempting to set the DestinationPageUrl attribute for my asp:Login control. For some reason, it required me to use both this and the OnLoggedIn event together (I was not aware of this events existence before Zerkey pointed it out). The Additional question mark in the return URL was also causing issues, so here's what I did in Login.aspx.

Markup:

<asp:Login ID="LoginUser" runat=server" EnableViewState="false"
       RenderOuterTable="false" OnLoggedIN="UserLoginOnLoggedIn">...</asp:Login>

Code:

protected void UserLoginOnLoggedIn(object sender, EventArgs e)
    {
        string itemid, itemdept;
        try
        {
            s1 = Request.QueryString["ItemID"].Trim();
            s2 = Request.QueryString["Dept"].Trim();
        }
        catch
        {
            //makes strings null if querystrings aren't present
            s1 = "";
            s2 = "";
        }
        string returnUrl = Request.QueryString["ReturnUrl"] + "&ItemID=" +
            Request.QueryString["ItemID"] + "&Dept=" +
                        Request.QueryString["Dept"];
        if ((!String.IsNullOrEmpty(returnUrl) && !String.IsNullOrEmpty(s1) && 
        !String.IsNullOrEmpty(s2)))
            LoginUser.DestinationPageUrl = returnUrl;
        else
            LoginUser.DestinationPageUrl = "~/Default.aspx";
        Response.Redirect(LoginUser.DestinationPageUrl);
    } 

这篇关于ASP.NET RETURNURL具体的搜索结果页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆