why image address must change when controller changed? - asp.net-mvc-4

in my sample application (mvc4 razor) i have a picture in my root solution in directory like "\files\mypic.bmp" and i have a area named members and this area has a controllers "home"and "settings" .
controllers actions imageUrl IE address bar
home index "\files\mypic.bmp" localhost:3251\home
settings home "..\files\mypic.bmp" localhost:3251\settings\home
when i use this image in home view i use this addrress of my image "\files\mypic.bmp" and explorer shows my pic but when i go to setting controller and home action i must use this address until explorer shows my picture ,"..\files\mypic.bmp" why this is and how can i make one address for all views and controllers

Use Url.Content to get the relative path:
#Url.Content("~/files/mypic.bmp")
The issue is that, when you use relative paths like those listed in the OP, the browser interprets them as relative to the current URL. Hence, they resolve to different places depending on whether the current URL is \home or \home\server.

Related

Images are not displayed properly in .net 5

In one control I try to display images using JavaScript. Everything is fine as long as I am in the URL controller
https://localhost:44300/Campaigns
But when I refer to the index, the images are not displayed, even though I am on the same page or after the Redirect ("Index").
https://localhost:44300/Campaigns/index
The root address does not seem to be working properly
This is my image address when it works properly in Campaigns
https://localhost:44300/uploads/f09ef469-0893-4089-8491-78707d097b0e.jpg
This is my image address when it does not work properly in Campaigns/Index
https://localhost:44300/Campaigns/uploads/f09ef469-0893-4089-8491-78707d097b0e.jpg
The CSS and js address images in the layout work well, and I used UseStaticFiles() in the Configure.
It is because you are referring to the images with a URL that is relative to your current page. You need to use a URL that is relative to your site root. You can change this by prefixing the URL with / where you are constructing them.
Eg instead of something like
uploads/f09ef469-0893-4089-8491-78707d097b0e.jpg
Use
/uploads/f09ef469-0893-4089-8491-78707d097b0e.jpg

Piranha CMS UI menu returns empty on post page

I have the default template menu from the piranha install. It works very well for all the pages of the site, but when it comes to viewing individual post pages the menu bar is empty, even when I specifically define root node as the startpage of the site.
Why is this? Can I make UI.Menu output the same html as on the other pages of the site in any way?
If you specify a root node, or start level for the menu, that page, or a child of the page has to be active in order for the menu to render. This is the logic that enables you to easily render submenus by typing:
#UI.Menu(StartLevel: 2)
When you render a post you don't have a selected position in the site map, so rendering the menu from a certain root node will most likely return empty. However, rendering the level without a root node should give you a menu, for example:
#UI.Menu(StopLevel: 2)
To help you out I need to know just how you're invoking the menu-helper from you .cshtml file.
Regards
HÃ¥kan

Image slider link to internal or external page on Sitefinity

(Sitefinity 6.x)
I am trying to create an image slider where each image in the page links to an internal or external page. I created a separate library for all the images that I want to show on the slider then using custom MVC widget I display the images in a slider.The problem that I have is there is no place in the image where I can link the image to open an existing internal page or external website.
Is there a way to add a properties to the original Image properties? so that users can select a page (using some sort of page selector just like in the navigation widget) or type in external page to link. If that is not possible, could you give me some ideas how to implement this?
I've been creating image rotators using Module Builder in Sitefinity. What you could do is go to Administration -> Module Builder -> Create a Module, call it Image Slider, call the content type Slide. Add a couple fields, for the first call it Image and select Media for the type, this will use an image selector for the interface, then add another field called Link and use Short text for the type, this will hold the url. Unfortunately, Sitefinity doesn't include a Page Selector control as an available field yet so a text field will have to do. Save and activate your module, it will show up under Content -> Types of Content. Go ahead and add a few slides. Sitefinity has created a couple of widgets when you created the module, so if you edit a page, you'll see them under the "Content" widget section, probably at the bottom. Drag it on the page and set it to use the list template. Now open up the Sitefinity Explorer window in their Thunder Visual Studio plugin, under Common Widget Templates, you'll see an Image Slider folder, you'll want to edit the list template since you'll be outputing all the slides into some carousel markup or something. From here you can use the default Sitefinity image control and bind the link to a hyperlink that wraps the image control, this will link each image to whatever is in that field.
Hope that helps.

how to prevent changed url in the browser bar from reflecting in the website content?

how to prevent the change in the url of the browser bar from reflecting in the website content's URLS...
here is the situation,
in my current web app, I am using this
$this->createUrl(Yii::app()->controller->id ."/". Yii::app()->controller->action->id, $params)
to generate href of the hyperlinks... now the problem is,
when I type in the browser bar like e.g
www.mysite.com/blahblahblah/subcategory/c1
the blahblahblah, also reflects to the webpage content hyperlinks,because of the Yii::app()->controller->id that I passed to the createUrl function...any work around for this ?..., what i want to happen is, no matter what string is typed in the place of the controller name via the browser bar, it won't reflect in the webpage content hyperlinks ..
so how ?
the answer was, I took the ID from the URL ,created a simple Helper function and used that to return the correct value of category/subcategory and outputs it in the view source no matter what change is done via the browser bar

change the anchor (location.hash) in the address-bar

I have an FB application that uses the anchor (document.location.hash) to set tags on different elements (for example the current TAB#, the group# that is displayed...).
So whenever the user changes these elemets, I change the anchor (location.hash) and it adds #tag=...
to the URL in the address-bar (and when the user copy the link and sends it to another user) he is redirected to the specific view (on the same page).
It works well when the app is a standalone site.
But when I put it under FB application (apps.facebook.com/myapp) - it does not change the URL in the address-bar (but when I read the document.location.has I see the change). I think maybe it is because my app is inside an IFRAME.
If it cannot be fixed, maybe there is a Facebook API that changes the hash part in the URL!!!
This is not possible to change the parts of location object of parent frame if it's served from different domain... You can only change the whole location by setting it to new value:
window.top.location = 'http://example.com';
Actually document.location always refers to current document, while window.location refers to top level document and represent the URL that user see in address bar of the browser.
So generally you changed the hash for current document and if it's opened as standalone site user sees that in address bar, but once running in frame (application canvas) user doesn't see the URL of that page, but parent frame which located on other domain and subject of cross-domain policy.