So, i am creating an ASP.NET(MVC5) application, on which i want to show an image using an img tag like that:
<img src='#Url.Content(Path.Combine(Server.MapPath("~/Products-Data"), product.Name, product.ThumbnailImage))' />
The problem is that no browser actually load the image. The fun thing is that the link generated by the razor engine is valid, and i can see the image if i open it from another browser tab. After some searching i noticed that in the chrome console, there was this error:
I found a lot of topics regarding this error(change settings in web.config, use the --allow-file-access-from-files flag and e.t.c), but none of these actually worked. This is going to be a real-world application ... but for the time being i need to test it locally, and check if everything works properly. Any work around's here folks ?
You just need to generate the path using relative path, resolving it to the absolute path wouldn't work, as it will be the path of the server's particular drive location which is most of the times outside of the working directory of the web application and it is not possible for the browser to fetch the resource using physical path, so it wouldn't work for you.
You would need to do do it something like :
<img src="#Url.Content(String.Format("~/Products-Data/{0}/{1}", product.Name, product.ThumbnailImage))" />
and it would be more better if you pass it via Model object the relative path and the view just have displaying code, view should not contain logic to generate the path.
Hope it helps you!
Related
i got assigned to a project regarding webdevelopment, which i have very little experience in and am currently trying to understand the structure of the webpage. Right now I can't understand where some of the html code/files are located on the webservers directory. Looking into it from the browser and using webdeveloper tools on a certain page I can see that its named "register.cs" and placed in a certain folder. Looking into the webservers directory I can't find anything related to it not even by searching the whole folder. Does someone understand? The website was apparently coded in C# using blazor ยด.
Right now i have a folder with another folder inside of it. The two folder names are called "pc details" and "pchardwaredetails"
When on a page in "pchardwaredetails" i want to return to a page in "pc details" using a button and response.redirect() but the file paths are just getting too complicated for me. What might the file path be from a page called "Details" in "pchardwaredetails" to a page called "viewMore" in "pc details"?
Also please feel free to explain how paths work so i know for future
thanks
Usually the Referrer of the page (a HTTP header), tells you what page you've come from so to go back you should just be able to do:
Response.Redirect(Request.UrlReferrer.ToString());
That's assuming you came from PC Details. However if you land on PC Hardware Details from some other page then that won't work, you would have to hard code the back feature.
You can simplify ASP.NET paths and use ~, for example:
Response.Redirect("~/some/path/pc_details.aspx");
I just started an asp.net c# project and I was trying to change the text-align of the .title and background color of the .header. I add the required code to the style sheet, but nothing changes in the header of the form. I'm probably missing something simple here, can someone point me in the right direction?
Stylesheets are usually cached by the browser to speed up browsing.
You can either force-refresh (SHIFT+F5) or append a value to the stylesheet path to cache-bust it.
style.css?v1
By changing v1 whenever you want a change to be forced out to all browsers, it will replace the cached version as resources are cached per URI.
Just try stopping your Local development server and do clean and build solution before running the application.
Even clear your temporary internet folder which may contain stale copy of your css file.
Right clicking in the markup view , you should see an options that says view in browser. This should reload anything cached.
I've been looking for a file hosting site to host my files and my friend offered me a premium account on Box.net.
The problem in this host site (and on many others) is that the links arent guessable, they cant be predicted. That means: If you upload 2 images called "1.jpg" and "2.jpg", the links aren't like
"www.host.com/omar/1.jpg , www.host.com/omar/2.jpg" ,
instead, they are like
"www.host.com/qweqwasd , www.host.com/123lqqwje" ..
So I cant use them on my application since I upload a lot of small site and I cant copy each link manually, it will take days.
Is there a way to override this problem in a program? maybe run a script to get all the links on the site?
When you upload a file, presumably the page shown afterwards gives the link - so just parse that page and extract the link from it.
Just think about how you'd get the link if you were a human, and do the same thing in code. (I assume you're already performing the upload in code.)
Alternatively, use a different file hosting site, which lets you specify the filename.
I am using the Tiny slideshow in my asp.net page. It works fine in all the Browser and here is the LINK, But my problem starts when I include that page in my master page and display the same. the Jquery stop working in Internet explorer.
http://www.spareach.com/public/xtemp8.aspx?userid=22&AspxAutoDetectCookieSupport=1
I am tired a lot for this.
Can any one help me please.
your script interpreted by ASP.NET Session. the actual URL of file is http://www.spareach.com/lightbox3/script.js. if you put the absolute URL then they work fine. hope this helpful
If you include that in another page, your relative link to the .js file is going to be invalid. So, your options are to make it absolute (http://www.something.com/folder/tiny.js) or to include the .js from the head or common document, if you use that structure.