Web Forms :: Relative Paths With Master Pages?
Sep 28, 2010How do I deal with master pages and relative paths especially when dealing with sub-folders?
View 1 RepliesHow do I deal with master pages and relative paths especially when dealing with sub-folders?
View 1 RepliesWhat is the correct way to reference an image in ASP.NET for live deployment on IIS? The following works in dev and production:
<asp:ImageButton ID="ibnEdit" runat="server" OnClick="ibnEdit_Click" ImageUrl="~/App_Themes/Default/images/one.png" Visible="false" ToolTip="Edit" />
The following doesn't work in either: (why not?)
<img src="~/App_Themes/Default/images/two.gif" />
The following works in dev but not in production:
<img src="../App_Themes/Default/images/two.gif" />
I have a website, lets call it mywebsite.com. I also have a blog at mywebsite.com/blog. I have made a URL rewrite rule so it can be accessed from blog.mywebsite.com. The issue is that all my root relative paths (~/) do not work when viewing the blog from blog.mywebsite.com. Ok, say if there is a link on my blog that goes to a blog post that is at ~/blog/post.aspx?id=1. It will then go to blog.mywebsite.com/blog/post.aspx?id=1 which is actually, mywebsite.com/blog/blog/post.aspx?id=1 and that does not exist.
View 3 RepliesMy WebApp is part CMS, and when I serve up an HTML page to the user it typically contains relative paths in a.href and img.src attributes. I currently have them accessed by urls like: ~/get-data.aspx/instance/user/page.html -- where instance indicates the particular instance for the report and "user/page.html" is a path created by an external application that generates the content. This works pretty reliably with code in the application's BeginRequest method that translates the text after ".aspx" into a query string, then uses Context.RewritePath(). So far so good, but I've just tripped over something that took me by surprise: it appears that if any of the query string ("instance/user/page.html") happens to contain a plus sign ("+") the BeginRequest method is never called, and a 404 is immediately returned to the user.
So my question is two-fold:
Am I correct in my belief that a "+" would cause the 404, and if so are there other things that could cause similar problems? Is there a way around that problem (perhaps a different method than BeginRequest)? Is there a better way to preserve relative URL paths for generated content than what I'm using? I'd rather not require site admins to install a 3rd party rewrite tool if I can help it.
I have my UserControls in a ~/Controls folder in my solution:
/Controls/TheControl.ascx
If specify the following:
<a id="theId" runat="server" href="./?pg=1">link text</a>
ASP.Net seems to want to rewrite the path to point to the absolute location. For example, If the control is on [URL] the link href will be rewritten to read
<a id="munged_theId" href="../../Controls/?pg=1>link text</a>
Why does Asp.Net rewrite these control paths, and is there an elegant way to fix it?
I just want the anchor control to spit out exactly what I tell it to!!! Is that so hard?
EDIT:
I've basically done what Kelsey suggested. I knew I could do it this way, but I don't like adding markup in my code when I want something relatively simple. At least it solves the problem:
Aspx page:
<asp:PlaceHolder ID="ph" runat="server"></asp:PlaceHolder>
Code-behind:
var anchor = new HtmlGenericControl("a") { InnerText = "Previous" + " " + PageSize) };
anchor.Attributes["href"] = "?pg=" + (CurrentPage - 1);
anchor.Attributes["class"] = "prev button";
ph.Controls.Clear();
ph.Controls.Add(anchor);
As you can see by the amount of code needed for what is essentially supposed to be be a simple and light-weight anchor, it's not the most optimal solution. I know I could use a Literal but I figured this was cleaner as I'm adding more than one anchor.
I have a few css files, javascript files and images referenced in my master page. When I do a "View Source" of the pages that use this master page, I can see that the css files are showing correct paths but javascripts and images don't. I tried using "~" in path but nothing worked so I used relative paths.
If I have a path for css file as "../../css/blah.css" and a page that is in sub-folder uses this master page, it correctly shows the path as "../../../css/blah.css". But the images and javascript paths continue to show the original path (hence broken images, javascript errors, ...).
A javascript source listed as src="../../scripts/blah.js" continues to show as "../../scripts/blah.js" instead of "../../../scripts/blah.js". Same thing with images. I did try "~/scripts/blah.js" and "~/images/blah.gif" but still can't find it.
I have got a master page(Project>>MasterPages>>MainPage.master) and some images in that page with some path like "../../Images/bg_main_menu.png".
I refer this master page in two forms. One of those form is oresent in the path :
Project>>Forms>>Form1.aspx and the other one is : Project>>Forms>>NewFolder>>Form2.aspx
Now for Form2.aspx the image is not getting loaded.
I tried the image path with "~Images/bg_main_menu.png". But it is not working.
I have a problem with my paths.hen I look at the default page that has my logo on the site.master the image (on site.master) shows fine in my browser:http://localhost:50033/Img/Logos/ahn_logo.pngAs soon as I click on a link like "About Us" the view gets returned but the image path is now:http://localhost:50033/Home.aspx/Img/Logos/ahn_logo.pngand it does not show.Why does the path of the master page image change ?
View 3 Repliesi'm developing a site using VS2010 and with my windows vista busniness OS. i used the default VS2010 wizard for new web application to create it. included a folder in the root directory and created new aspx pages to derive from the master page in the root directory of my site. everything shows on the new pages except the jpeg image logo in the master page. But other aspx pages i created in the root directory shows every thing fine.
View 1 RepliesCurrently I'm doing common functionality required throughout my site inside of my masterpage. What I want to do is move this functionality to a BaseClass so All my pages inherit from the Base Class. However, I'm not sure how to set this up interms of c# code with regards to Using a Base Class and then having a masterpage applied to my aspx pages that i create.
View 5 RepliesQuestion about paths while working in Visual Studio. In my master page I have some paths to load css files as well as javascript files.
My first question is if I use relative paths, should the relative path be from the location of the master page file? For example if I keep all my master page files in a folder off the site root called MasterPages should I assume that is the starting point for my relative paths to load the css files? If that master page is used to wrap an aspx file several directories down the tree is the hard coded relative path still valid?
Second question, is there a way to use absolute paths so that everything works on my local machine as well as when I move the files up to the webroot? For example my app path on my local machine may be localhost/myappdir/default.aspx but when i move the app to the server there is no myappdir and the default.aspx is in the webroot. I do not want to have to change paths in the files after they are moved up to the server. currently I have;
src="<%= VirtualPathUtility.ToAbsolute("~/lib/css/style.css")%>"
but this way Visual Studio cannot find the css file to update intellisence
My requirement was to share master files among diff projects i read this doc [URL] so i use this technique to share msster pages among my diff projects in a soln but i dnt know how to reference such shared master page as if i use such
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="../masterPages/masterInvGen.Master"
I got a Master page and nested master pages in the subfolders.
Top Level Master page
Second Level Master page inherited Top Level Master page
Third Level Master page inherited Second Level Master page
However, changes (i.e. new images & alt. name) that I made in the Top level master page did not apply to the second or third levels.My webpage has a correct front page but not in the sections. How can i correct this ?
How can we add titles to each content pages which inherits from mater pages in asp.net?
View 1 RepliesHow do you implement SquishIt to bundle Css/Js across View Pages and Render it in the Master page? I thought I could use a ContentPlaceHolder above the Render portion, but there seems to be some odd behavior where it sometimes adds 3 files (1 in the view page and 2 in the master page) but other times will ignore the file added from the View Page.
Index.aspx
<asp:Content ContentPlaceHolderID="CssFiles" runat="server">
<% CssHelper.Add("home.css"); %>
</asp:Content>
Site.master
<asp:ContentPlaceHolder ID="CssFiles" runat="server" />
<% CssHelper.Add("reset.css"); %>
<% CssHelper.Add("master.css"); %>
<%=CssHelper.Render() %>
My current solution is a Static wrapper around SquishIt's static Bundle class that keeps the BundleBuilder in HttpContext.Current.Items.
I'm curious if this has been done successfully and how so.
Is it possible with ASP.NET Master Pages to create content pages dynamically?That is, I know we can create content dynamically, but the content pages themselves,can those be created programmatically? I want to give my users the ability to define new content pages (i.e. Categories: Sofas, Tables, Lamps, and add/delete as they see fit) through a management panel. The resulting content pages should have proper URL naming, so that they index properly.An example: http://www.example.com/products/Lamps/contentpage.aspx.Is there a demonstration of this somewhere I can view?
View 4 RepliesI have over 300 content pages to create. Each has some standard styling. I would like to generate these pages, and was just wondering if there is a utility in web developer 2008 express to do so (otherwise I will just build one - but it would be great not having to do so!)
View 1 RepliesI have a master page setup that is used throughout my site that is basically a header with a menu. I recently added a textbox and a button to this master page which is to be a quick search box that is available anywhere in the site. When a user enters text into the search box and hits the button, I need to load the actual content page which is used to search and show search results (which also uses this same master page), and have the text entered available so the search can be triggered automatically. Again, this search text box and button is now in my master page so it could be triggered from anywhere in the app... it serves as a convenient way to do a basic search from anywhere in my app, without having to first navigate to the actual 'search page' that already exists. You can also navigate to the actual search page, which uses the same master page, where there is many more search options.I'm thrown off by the master page arrangement, which I have not used until this project. What do I do?
View 4 Replieswhat is difference between Master page and Master Pages in ASP.Net. Is both are same or different.
View 3 RepliesIs there a way to assign pages created from a master page with their own meta tags? I know that some search engines don't weight meta tags very highly, but I still would like to use them if possible.
View 3 RepliesI have spent time learning coding using master pages in inline styles and my sites are functional but look lousy. Now I am turning to learning CSS and to make my sites look more professional.
I wanted to try to convert my sites to using CSS. So I ask the question which is better option?
Also does anyone who develops in a corporation know if Master pages are use much?
I have been working on a fun little project just to build my skills as an ASP.Net developer. I have learned quite a bit thus far, and don't normally post questions in forums. Google and the books I own generally do the trick for me. But for this question I would like some community input.
I am developing a simple blog platform in ASP.Net / C#. Eventually I hope it will basically be a clone of how Wordpress works. Again, this is mostly a learning project for myself and I realize there are many projects out there doing what I am doing in .Net.
Anyways, the question I want some input on is whether I should use themes or master pages to customize the look and feel of the site. As I understand it, a theme mostly just changes colors and such, but CAN do much more. Whereas a master page can easily change the look and feel of an entire site.
What are the pro's and con's of either route, and what would y'all recommend? I'm not really looking for code examples here, just input on what y'all would think is the best route to pursue.
i Have one ascx file which is include login control... i want to find that login control from the page.
let say.. me.ascx file..
and me.aspx file.. me.aspx file master with me2.master and me2.master master with me1.master... me.ascx file is in the me1.master ...
i am looking for login control from me.aspx.
using
login = page.master.findcontrol("login1");
but cant find control...
have 2 master pages in my application (master A and master B). The master A is a general menu. The master B is a user menu. Of course master B just appears when the user is logged.Now I'm using stylesheets. I want a style sheet for master A, another one for master B and others (one for each one of the pages of websites).For master A is very simple... I declare a stylesheet in the <head> using <link> tag.I think its not difficult for each page as well. I don't know how to I do it, but I think I can declare inside <%@ Page %> tag. Theres a property called "StyleSheetTheme".The problem is master page B, because I can't use the <head> tag (because master B uses master A) and I can't use <%@ Page %> tag, because its a master page.
View 1 Repliesi have tow master pages .i want to switch between them according to a some condition
i work with this code to load master page what i want
at every page
[Code]....
i wirite this code for every page in my application
how can i write this code only once such as in Global.asax