下面的普通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按预期重写,但被调用的页面呈现“完全错误”。
我在这里缺少什么ppl?
感谢您提前关注此事。 任何解决方案都将不胜感激。
(大大缩小了被调用的页面,但在上面两个不同的调用中表现相同) 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>
答案 0 :(得分: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();
}
注意,您需要检查查询字符串和路径数据。
您需要确保的另一件事是样式表等的路径是正确的。
答案 1 :(得分: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>
**编辑以手动解析与应用相关的网址