-1

下面的普通 Href 可以正常工作并正确呈现被调用的页面,但是 URL 没有隐藏。

<asp:Repeater ID="rCompany" runat="server" DataSourceID="sdsCompany" >
<ItemTemplate>
<div class="col4" id="trip_third">
<a href="discover_detail.aspx?Companies_PKID=<%# Eval("Companies_PKID").ToString() %>">    
    ....... 
</a>
</div>
</ItemTemplate>
</Repeater>

在下面添加 Global.asax 后...

protected void Application_Start(object sender, EventArgs e) 
{
//Code that runs on application startup
RegisterRoutes(RouteTable.Routes);
}

public static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute(
"RouteForDiscover_Detail",
"discover_detail/{Companies_PKID}",
"~/discover_detail.aspx");
}

并将 Href 更改为 ...

<a href="<%#GetRouteUrl("RouteForDiscover_Detail", new {Companies_PKID=Eval("Companies_PKID").ToString()})%>" >

URL 按预期重写,但被调用的页面呈现“完全错误”。

我在这里错过了什么?

提前感谢您对此事的关注。任何解决方案将不胜感激。

(大大缩小了调用页面,但与上述 2 个不同调用的行为相同) discover_detail.aspx (这不是我的 HTML 代码) 另请注意,为了简单起见,SelectCommand(s) 是硬编码的,以确保它们不是原因。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="discover_detail.aspx.cs" %>
<%@ Import NameSpace="System.Web" %>
<%@ Import NameSpace="System.Web.UI.WebControls" %>
<%@ Import NameSpace="System.Web.UI.WebControls.WebParts" %>
<%@ Import NameSpace="System.Web.UI.HtmlControls" %>
<%@ Import NameSpace="System.Web.Security" %>
<%@ Import NameSpace="System.Web.Routing" %>
<!DOCTYPE HTML>
<script runat="server">
new void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["Companies_PKID"] == null)
{
sdsCompany.SelectCommand = "SELECT * FROM [DiscoverShare].[dbo].[Companies] OUTER APPLY (SELECT TOP 1 * FROM [DiscoverShare].[dbo].[Image] WHERE Image.Company_PKID = Companies.Companies_PKID) i1 WHERE Companies.Companies_PKID = 464";
sdsImage.SelectCommand = "SELECT * FROM [DiscoverShare].[dbo].[Image] WHERE Image.Company_PKID = 464";
}
else
{
sdsCompany.SelectCommand = "SELECT * FROM [DiscoverShare].[dbo].[Companies] OUTER APPLY (SELECT TOP 1 * FROM [DiscoverShare].[dbo].[Image] WHERE Image.Company_PKID = Companies.Companies_PKID) i1 WHERE Companies.Companies_PKID = 464";
sdsImage.SelectCommand = "SELECT * FROM [DiscoverShare].[dbo].[Image] WHERE Image.Company_PKID = 464";
}
}
</script>
<html lang="en-us" class="no-js">
<head>
<meta charset=utf-8>
<title>DiscoverShare | Explore.Achieve.Connect</title>
<link rel="shortcut icon" type="image/x-icon" href="../assets/images/favicon.ico" />
<link href="css/bootstrap.min.css" rel="stylesheet" />
<link href="css/master.css" rel="stylesheet" type="text/css" />
<script src="js/scrolltopcontrol.js" type="text/javascript"></script>
<script src="js/modernizr.js" type="text/javascript"></script>
<link rel="stylesheet" href="css/flexslider.css" type="text/css" />
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<link rel="stylesheet" href="css/ie.css">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no,maximum scale=1">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.flexslider-min.js" type="text/javascript"></script>
</head>
<body>
<asp:SqlDataSource ID="sdsCompany" runat="server"
         ConnectionString="<%$ ConnectionStrings:DiscoverShareConnectionString2 %>"
    SelectCommand="SELECT * FROM [DiscoverShare].[dbo].[Companies]
                        WHERE Companies_PKID = 517">
    <SelectParameters>
        <asp:QueryStringParameter Name="Companies_PKID" 
                 QueryStringField="Companies_PKID" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="sdsImage" runat="server"
         ConnectionString="<%$ ConnectionStrings:DiscoverShareConnectionString2 %>"
         SelectCommand="SELECT * FROM [DiscoverShare].[dbo].[Image] WHERE Image.Company_PKID = 517">
    <SelectParameters>
            <asp:QueryStringParameter Name="Companies_PKID" 
                 QueryStringField="Companies_PKID" Type="Int32" />
         </SelectParameters>
    </asp:SqlDataSource>
</body>
<form id="login" runat="server">
        <div class="navbar navbar-inverse navbar-fixed-top">
            <div class="navbar-inner">
                <div class="container">
                    <a class="brand" href="default.aspx"><img src="assets/images/logo.png" height="40" width="200" /></a>
                    <div class="nav-collapse collapse pull-right">
                        <ul class="nav">
                            <li class="active"><a href="#">Home</a></li>
                            <li><a href="AddActivity.aspx">Add Activity</a></li>
                            <li><a href="ReviewActivity.aspx">Review Activity</a></li>
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown"><asp:LoginName ID="LoginName2" runat="server" Font-Italic="False" Font-Names="verdana" Font-Size="10pt" /> <b class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    <li><a href="mytrips.aspx">Bucket List</a></li>
                                    <li><a href="settings.aspx">Settings</a></li>
                                    <li><a href="findfriends.aspx">Find Friends</a></li>
                                    <li class="divider"></li>
                                    <li class="nav-header">Login/Out</li>
                                    <%--<li><a href="#">Separated link</a></li>--%>
                                    <li id="login_button"><asp:LoginStatus ID="LoginStatus2" runat="server" Font-Bold="True" Font-Names="verdana"
                                         Font-Size="8pt" ForeColor="White" 
                                         LoginImageUrl="~/assets/images/login.png" LogoutAction="RedirectToLoginPage"
                                         LogoutImageUrl="~/assets/images/logout.png" LogoutPageUrl="~/login.aspx" /></li>
                                </ul>
                            </li>
                        </ul>
                    </div><!--/.nav-collapse -->
                </div>
            </div>
        </div>

    <div id="footer_wrap">
        <footer class="row">
            <div class="standard-footer">
                <p><span style="margin: 0 10px;">&copy;2012 DiscoverShare&trade;</span> | <a href="/about">Business</a> | <a href="/contact">Brand</a> | <a href="http://twitter.com/" target="_blank">About Us</a> | <a href="/terms">Privacy</a> | <a href="/privacy">Jobs</a> | <a href="/privacy">Terms</a> | <a href="/privacy">Help</a></p>
            </div>
        </footer>
    </div>
    <script src="js/gumby.min.js" type="text/javascript"></script>
    <script src="js/jquery.mousewheel.min.js" type="text/javascript"></script>
    <script src="js/jquery.easing.1.3.js" type="text/javascript"></script>
    </form>

4

2 回答 2

0

我认为您需要为我们提供更多代码才能完全提供帮助,但我有一种强烈的感觉,这是您的问题:

在您的第一个示例中,您使用的是查询字符串来传递Companies_PKID,所以我猜您后面的代码类似于:

if (!String.IsNullOrEmpty(Request.QueryString["Companies_PKID"]))
{
    string blah = (Request.QueryString["Companies_PKID"]).ToString();
}

现在您需要以不同的方式获取值:

if (Page.RouteData.Values["Companies_PKID"] != null)
{
    string blah = Page.RouteData.Values["Companies_PKID"].ToString();
}

请注意,您需要同时检查查询字符串和路由数据。

您要确保的另一件事是样式表等的路径是正确的。

于 2013-07-02T14:22:55.747 回答
0

由于请求的 URL 位于虚拟子目录 (discover_detail) 中,因此您所有的相对引用现在都是错误的。您需要将所有对图像、样式表等的引用更改为使用相对于应用程序的版本。

不是唯一的,但这应该让你更接近:

<link runat="server" rel="shortcut icon" type="image/x-icon" href="~/assets/images/favicon.ico" />
<link runat="server" href="~/css/bootstrap.min.css" rel="stylesheet" />
<link runat="server" href="~/css/master.css" rel="stylesheet" type="text/css" />
<script src="<% Page.ResolveClientUrl("~/js/scrolltopcontrol.js") %>" type="text/javascript"></script>
<script src="<% Page.ResolveClientUrl("~/js/modernizr.js") %>" type="text/javascript"></script>
<link runat="server" rel="stylesheet" href="~/css/flexslider.css" type="text/css" />
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<link runat="server" rel="stylesheet" href="~/css/ie.css">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no,maximum-scale=1">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script>
<script src="<% Page.ResolveClientUrl("~/js/bootstrap.min.js") %>"></script>
<script src="<% Page.ResolveClientUrl("~/js/jquery.flexslider-min.js") %>" type="text/javascript"></script>

** 编辑为手动解析应用相对 URL

于 2013-07-02T20:10:47.747 回答