下面的普通 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;">©2012 DiscoverShare™</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>