I'm an SEO by profession and I have recently developed a database driven ASP.NET site. I have a problem with my website's internal linking. My links are shown as doPostBack, but I want them to display the actual URL so that search engines can crawl them.
Current: This is link pattern in my sidebar. All links are in this format
<ul>
<li><a id="linkHome" href="javascript:__doPostBack('ctl00$linkHome& #39;,''">Home</a></li>
This is just one link from the sidebar. All links are in this format. I want them to be like
<li><a id="linkHome" href="http://www.example.com">Home</a></li>
How can I make this happen?
Tell your developer to use normal href links for those if they're links instead of asp:LinkButton which is what he's using I think. Alternatively move to MVC and use the MVC router. He's using server side controls for what (you're telling me) can be client side links (standard anchor tags) The asp:LinkButton causes server side processing just to handle a link which is silly if the pages can be reached directly with no need to make a server request.
edit:
For a little more detail, here's what your developer is probably doing, either:
<asp:LinkButon runat="server" id="linkHome" OnClick="linkHome_OnClick" Text="Home" />
or maybe
<asp:HyperLink runat="server" id="linkHome" NavigateUrl="example.com" Text="Home" />
what he should do is simply:
Home
Related
For example, I have two sibling pages Index.aspx and Orders.aspx in one folder. On the page Index.aspx I have the link to Orders.aspx. What is the correct way to implement this:
<a runat="server" href="~/Orders.aspx">
or
<a href="Orders.aspx">
I know what runat="server" does (server-control, performance impact etc.).
You really never need to run markup with a run at server tag if it's never used in code behind, if it is then you should use a ASP.NET control for it.
So just a hyperlink without runat=server would be fine.
It's always best to use ASP.NET controls on your page though if an upgrade in the future could require language translations, or have some logic assigned to them in the future. So always plan ahead on your designs.
If both views are in the same folder, than the second one:
<a href="Orders.aspx">
The deal is that when you have the following on your site it works:
Click Me!
But the above fails to work if that site is a nested application.
I have seen two solutions to this opportunity in asp.net.
The first solution that I found was to add the following:
<a runat="server" href="~/Some/Path/file.aspx" class="button">Click Me!</a>
I have not tried this because I feel it would add more crap to your view state.
The solution that I have tried is:
Click Me!
The question is, what is the preferred method of addressing paths in nested applications?
You want to use HyperLink server control. It is meant for that kind of thing.
<asp:HyperLink runat="server" ID="HyperLink1"
NavigateUrl="~/Some/Path/file.aspx"
CssClass="button">Click Me!</asp:HyperLink>
Render as
<a id="HyperLink1" class="button" href="/Some/Path/file.aspx">Click Me1</a>
ASP.Net HyperLink control uses ResolveClientUrl to resolve the given url, so you do not need to do anything.
Im new in Asp. I've created a new C# simple web site.
it contain navigation menu and 2 pages.
Navigation menu is something like:
<asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
And all master page is in form which handle menu issues.
Now i'm adding a new web form which contain
<form runat="server">
And when i try to open this page on server it writes to me:
A page can have only one server-side Form tag.
How should solve this? should use common form tag?!?
By default ASP.NET pages already have a <form> tag that wraps the entire page. So if you add a further <form> tag you end up with nested forms which isn't allowed.
You can usually get away with dropping your inner <form> tag.
That is because ASP.Net uses only one form to handle everything. You can implement all the functionality using only one form - that is the approach of ASP.Net
You can read a small but nice article at W3 Schools
I'm just starting web-developing now (I do have experience with C#). And I've seen a recommendation to use Web.sitemap to have a list of pages of my website. Does this help? Will I be able to use this instead of having links on my web pages somehow? And what about being accessible to Google so my website will be found by searchers – will this help?
The Web.sitemap is not primarily a control to be used for your main navigation; it's meant as a navigational overview for the user and is typically only needed in large sites. It doesn't affect your SEO in any way - Google is more interested in the quality of your content.
A site map (NOT a Web.sitemap) is a list of pages on your site, and used in conjunction with a robots.txt file, CAN help your SEO. You can use the following tool to generate a site map automatically (although you'll nearly always have to hand tweak it as well):
http://www.xml-sitemaps.com/
The normal way to build navigation for a small/medium site is to create a set of links as an unordered set (ul/li) and style them with CSS.
It is possible to use Web.Sitemap as navigation source, though probably not recommended. I've used Web.sitemap driven navigation for a couple of sites I've developed. However, it really only works well if you have a simple site with static content pages. Here's the code I used for example:
<asp:SiteMapDataSource ID="MainMenuDataSource" runat="server"
ShowStartingNode="false" StartingNodeOffset="0"
StartFromCurrentNode="false" />
<ul id="jsddm" style="padding-top:10px;">
<asp:Repeater ID="MainMenuRepeater" DataSourceID="MainMenuDataSource" runat="server">
<ItemTemplate>
<li><%#Container.DataItem.Title%>
<ul>
<asp:Repeater ID="MainMenuRepeater_2" DataSource='<%# Container.DataItem.ChildNodes %>' runat="server">
<ItemTemplate>
<%#Utilities.GetSecondaryMenuItem(Container.DataItem, False)%>
</ItemTemplate>
</asp:Repeater>
</ul>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
Where Utilities.GetSecondaryMenuItem is just a helper function in our application that uses custom attributes from the sitemap nodes to control the display formatting of the secondary menu.
Links are a fundamental part of any website and there's no reason to avoid them.
A sitemap is just an XML file that defines the site structure, and it's used mainly by search engines to index sites. You can use them for other things too, like crumb trails for example, but they are not a substitute for hyperlinks.
I have a master page with links to other pages in the site. Those links use tilde paths (like "~/dir1/page2.aspx"). On most of the pages in the site that use this master page, there is no problem.
The problem only occurs on a few pages that use the master page. The links are VERY wrong; it tries to use the ~ as part of the link (so they are "http://server.domain.com/~/dir1/page2.aspx").
It's as if it is treating the tilde as a literal under certain circumstances.
Sounds like you're not properly resolving the URLs.
Are you writing ResolveUrl("~/")?
Also make sure that if you use ~/ that your controls are runat="server".
I just had this issue and the answer that worked best for me was to use the asp:Hyperlink control:
<asp:HyperLink ImageUrl="/Images/Logo.PNG" runat=server NavigateUrl="~/Default.aspx" />