I have one master page, in short there are two images on the master page (a logo at the top, and a fb link at the bottom).
I do however have an admin folder for the .aspx pages for when admin log in.
All non-admin pages need to access these two images with the src of image/logo.jpg and image/fb.jpg. However the admin pages need to access the image with the src of /image/logo.jpg and /image/fb.jpg.
Is it possible to achieve two separate paths depending on the folder, without having to create a second master page?
<img src="/images/yourimage.png" />
use Image Server control instead of html img tag or ResolveUrl method to handle generated url:
<img src='<%= ResolveUrl("~/images/yourimage.png") %>' />
Related
I am using HttpContext.Current.Request.Url.AbsolutePath as part of my security which the user needs to login before they access certain pages.
In this example and it works great. The user has to sign in before they view their profile.
if (Session["UserID"] == null)
{
Response.Redirect("Login.aspx/?ReturnURL=" + HttpContext.Current.Request.Url.AbsolutePath);
}
The end result looks like this:
http://localhost:54324/Login.aspx/?ReturnURL=/Profile_Page.aspx
The issue I am having is the pages are part of the master page. When the redirect occurs to the login page, nothing on the master page works. The navigation links do not fire, the images show broken links, etc. However when I access the Login Page directly everything in the master page works fine.
There's an extra forward slash in your redirect URL:
Response.Redirect("Login.aspx/?ReturnURL=" + HttpContext.Current.Request.Url.AbsolutePath);
^
Your login page still loads correctly because ASP.NET treats the slash as a separator for additional path information, similar to the way that a question mark is the separator for the query string.
But the extra slash causes a browser to resolve relative URLs for links and images relative to a child directory named Login.aspx instead of relative to the root of your application. For example, if you had the image <img src="Logo.png">, a browser would attempt to load Login.aspx/Logo.png. Removing the forward slash should fix the problem with the redirect:
Response.Redirect("Login.aspx?ReturnURL=" + Request.Url.AbsolutePath);
Nevertheless, visitors will still get broken URLs if they manually append the slash. To avoid this, use the built-in <asp:HyperLink> and <asp:Image> server controls, which will generate relative URLs taking the extra slash into account:
<asp:HyperLink runat="server" NavigateUrl="~/About.aspx" Text="About Us" />
<asp:Image runat="server" ImageUrl="Logo.png" />
<link href="CSS/make.css" rel="stylesheet" />
This an external css file for a page named "Default.aspx" which is located in "Root/Pages" directory.
so In "Root/Pages" we will have these:
Default.aspx
CSS/make.css
It will work fine if I launch Default.aspx from current location, But user can change the directory of Default.aspx from main page. Then in Code-Behind I will copy all of Pages contents into another directory.
Just think I will copy Default.aspx and CSS folder from Root/Pages to Root/Backup and try to launch Default.aspx from new location. In this situation it can not read and load external css file!
How can I change css href link dynamically from its container page's location?
For example changing href="CSS/make.css" to href="BackUp/CSS/make.css".
After some research I found that I should use Global and URL Routing, but I did not get any working result.
If you put the css file in the root directory then refer to it using:
<link href="/make.css" rel="stylesheet" />
It should now work even when you move your Default.aspx to another location. The downside to this is that it can clutter your root directory if you plan to use it for multiple different pages with different CSS files.
Let me know if it works and if I am understanding your question right.
function DynamicURL()
{
var URL='CSS/make.css';
var BackUp ='BackUp/';
if (Your condition when it changes directory)
URL = Backup + URL;
document.getElementById('Field').href= URL;
}
Don't forget to set ID to your link href field.
I would like to make a 1 pixel image that will reside on the html page to track page activity
I have a page http:/domain.com/mypage.htm
and I want to add <img src='http://www.test.com/myimage.aspx' /> somewhere in its body
When page is triggered I render an one pixel transparent image. I'm having an issue finding out the URL of the page that image is on. HTTP_REFERER header carrier the true referer of the page, and HTTP_HOST carries the URL of the image itself.
Is there a way to find out the HTML page URL that the image is on?
If you can't find it on any http header, you can always send some information like <img src='http://www.test.com/myimage.aspx?page=mypage' />.
If you can use javascript though, you don't need to display an image, use an ajax request instead.
You can analysis the request headers of myimage.aspx, the Referer header is the HTML page URL you're looking for. Besides, I suggest adding a timestamp with the <img> src link, like this:
<img src="http://www.test.com/myimage.aspx?t=1234567890" />
So that every time you refresh the HTML page, the browser invoke a new request to the image.
MySite.com
when I click site logo, wanna appear sitefinity home page. how to set href atrribute in sitefinity as sitefinity CMS is dynamic home page?
there are several ways to achieve this, depending on how you have your logo setup on the page.
Your home page is usually setup to load when you visit the top level domain, which is at the root of your site.
If this is the case and you have your logo defined in a .master page, you can easily set the link to be the root, like
<img />
If, on the otherhand, you have the image on a sitefinity page or template, you need to make sure that you're adding the image inside a ContentBlock, and not the Image widget from the sidebar. This widget is only used to disaply an image, not link one.
by adding the image to the content block, you can then select it and add a link from the radeditor toolbar to the home page (or any other page)
hope this is helfpul!
Another, rather easy way of doing this would be using your url http://www.mysite.com as href for the logo, which is not too bad either (Although not as dynamic anymore)
But still helpful, especially if you are using some code in your print.css that looks like this:
a:link:after,
a:visited:after {
content: " (" attr(href) ") ";
font-size: 90%;
}
and renders href links after your actual links on printed pages.
This would result in something like the below:
[your company logo] http://www.mysite.com
I have a JavaScript code which links to survey poll page. When I am embedding the JavaScript code in normal aspx page (without master page), I am getting the survey normally without any issues, but when I am embedding the same code in page which uses master page, I am getting blank page.
This way doesn't work: http://gyazo.com/27f38b5b04897cf0b17747eab05cf746
This way works: http://gyazo.com/c69d3b95afe4a0070cd09834e479a97f
Update
Using <script src='<%=ResolveClientUrl("~/Survey/xlaabsolute.asp?p=1")%>' type="text/javascript" /> renders the poll correctly but the button for voting doesn't do any postback http://gyazo.com/b39fcaa8de3438c8c2a625e3816ba4be.
I can see the content http://gyazo.com/b39fcaa8de3438c8c2a625e3816ba4be
Chances are it's how the script is referenced.
You're using a relative position in your src attribute which could potentially change if it's not in a location that allows Survery/... to be found. Maybe change it to /Survey/... so it always locates the file based on the root path and not where the document currently resides?
You can also make your script tag runat="Server" and reference the script using traditional ASP relative links: src="~/Survey/..." so it resolves correctly.
The way to resolve the issue and make it work regardless of where the control is being used is to use ResolveClientUrl as so:
<script src='<%=ResolveClientUrl("~/Survey/your_script.js")%>' type="text/javascript" />