My emails have images that come from database.
So, when I change the images the Images that are shown on my email will change
but the problem is that the images that are displayed are still the old one.
But If I go into the DOM and copy the src of the image and paste it into the address bar the downloaded image is the new image.
Its like there is some sort of cache problem or something. So I cleared the system cache but the image rendered is still the old one
Check these things
1. Server side - Are you clearing all the objects after sending the data to the client?
2. Client side - try by clearing the cache or Make sure you are having images with different names
Suggestion: Please update your question with client side and server side code so that we can guide you better.
It is not a cache problem. In .NET framework there is a copy of the database which gets created at your end to fetch the data at runtime. Due to this you're not getting the updated images from the DB.
To get the updated images, make sure your code accesses the database and fetches the images EVERY-TIME you need.
The key is to get the data directly from the database before displaying.
Also, provide more details for better solutions.
Related
I have a small website with couple different forms inserting data to sql. But the users have problem with it. The problem is that they seem to be going through them too fast that its not recording everything.
So i am trying to see if there was a way to store all the data locally and have it insert to sql at the end when they are done filling out forms. Is this possible?
For example:
I have a form that have 5 fields but 2 are auto populated and 1 entered manually and 2 are being inserted using bar code scanner. The bar code scanner is the last value required before being inserted, so i was hoping there was a way to insert that into locally store access database (not seen by anyone) and when they press "Finish" all that data from access will be inserted into sql.
Hope i painted the picture clear enough.
Let me know any and all possibilities.
EDIT: Here is the aspx and .cs, hope this helps. Yes i realize that i have validation for the bar code, but not sure why its slow. And i may have stuff cluttered. So please bear with me.
Sounds like you need to put that data in application session or cache and then flush the data to db.
Here are some other choices though:
Flat files (simply serialize your objects, use protobuf)
Use Embeded Db: SqlLite, VistaDb, Sql Server Compact...
Store data in the browser via localstorage (dom storage, this is html 5 feature)
I currently store a number of document preview images (jpg/tif) outside of my web root. There are 100s of them, so having this work efficiently is important.
The reason they are stored outside of the web root is that they contain data the only specific users/user groups may view (but each user can have 100s of documents they can view).
My current implementation is, when the user selects ‘view image’ an ajax call is triggered and this moves the image in question to a specific folder within the web root. The location is passed back and used to display the image to the user.
When the next image is clicked, the call deletes any existing images and copies over the requested image. At session logout / timeout the users image folder is emptied.
This has a few problems, but mainly:
Files are constantly being copied and deleted
There is the risk of images being left in the folder (issues with log off scripts)
The whole time an images is in the folder it could be viewed by another users (unlikely but possible)
Is there a better way of doing this? I looked at trying to combine the BinaryReader with the ajax call (as I hoped this would cut out the need to copy the files), but can’t see how to get the data back to be used by the JS in the calling page.
Alternatively is there a way of making selected Folders only accessible to given users based on some session criteria? (I can’t imagine there is but I thought it’s worth asking.)
So if anyone has any ideas on how this can be improved that would be great.
This is a c# ASP.NET app using Jquery.
Edit:
The image is displayed using ajax, this allows for preloading and also means the rest of the page does not need to be reloaded when they select the next/previous image.
It can almost be thought of as a javascript image swapper type situation, where the images are stored outside of the web root.
Thanks.
My current implementation is, when the user selects ‘view image’ an ajax call is triggered and this moves the image in question to a specific folder within the web root.
This is horrible idea. You realize you can just access the image data and pass it to web as stream with specific mime type, right?
Maybe try to write a method that will check user credentials by cookies, if it is not OK then load and send back some standard image that will say that user must log in to view file, if it is ok then load and show proper file from a path outside of root based on url parameter (with proper headers like content-type also often referred as mime-type ofc). Then link urls to that method with proper parameter(s).
You can easily find examples of code (like here) to display image in binary form from DB. You would need just to load them from some path outside of root, not DB.
Also you don't need to load it by AJAX - just add IMG with SRC pointing to URL of handler. Or redirect / open window if it needs to be downloaded not shown.
The issue was how to get an image to show via javascript that is not in the web root.
I created a generic handler (ashx file) that based on the session values (authentication) and submitted parameters would return an image.
That in turn is being called via AJAX.
have read many article and most of the article suggest httphandler or handler for image binding to gridview from SQL Server.
Is it possible to bind images from database to gridview without httphandler or handler?.
If yes than provide me sample code
My table schema: Table Name:- ImageGallery
Column Name DataTypes
Photo image
The above table stored the images in <Binary data>
Is it possible? Yes. Is it a good idea? Not at all, and here's why. An HttpHandler is a way of providing a virtual URL for the image. This allows the browser to handle the GET requests on its own, in an order that's efficient, and asynchronously. This further means that the initial GET request isn't burdened down with conceivably MB's of images.
The idea of a website is that it's more efficient to make a lot of smaller requests asynchronously than it is to make one massive request. Why? Because you're already at a disadvantage to provide the user with a good experience when disconnected from the server. Adding insult to that injury by making a massive request that could take minutes, isn't going to add to their joy.
Instead of storing image as Binary datatype in database, U can try an alternate Solution.
1. Make the column datatype as varchar or nvarchar.
2. Store your image in a seperate folder.
3. Fetch the url for that Image.
4. Save it in the Database.
5. Now in your gridview mention tha column data according to ur wish.
6. During Runtime the URL will refer to the content and the image will
be displayed in your Gridview.
I am creating application in which I would have database which users can´t edit. It just have data and it shows to user. I found that I dont have to use localstorage I just can add database to project and it is readonly. So I did it and everything is ok. Now I want to add images to my app and I am not sure what is better way. I can every image add to folder, in database store path to image and It´s very easy and It can do now. Or I found that I can store image in database as image (byte[]). What is better? Would be images in database smaller? Would be loading of images faster? If images in database is better solution have can I easy way add images to my existing database? Is there any article to do this in winforms? Thanks
Edit:
I'm glad that my question has so many answers and opinions. I want to explain more my needs. My application should have about 150 pictures and picture should be sized 150px and 100px. I want to app would work without internet connection. It could connect for updates but that´s all. Again thanks for all opinions :)
For our application, we found a hybrid approach worked best. We configured our SQL environment to support FILESTREAM and then imported all of our images. That gives us the flexibility of having the images 'in sql' while still storing the actual images to disk. Its a fast solution that may work well for you, too.
There are a lot of 'ifs', 'buts' and 'maybes' about where you put you put your images and I don't think there is a right or wrong way.
One thing worth mentioning is that if the application is business critical with high availability I would store them in the database, simply because the can be backed up with the rest of the data. Databases can be mirrored etc so having all the images treated as 'data' can be beneficial. Also if things get big and a web farm is employed and load balancers etc it helps when the images live in one place.
For me, I'd go with the database. But it all really depends on the scale of your application.
I personally would store all the images in isolated storage and in the database I would store the path to the image.
I would store all the images as a byte[] in the isolatedstorage
Nothing wrong with the answers already here but it really depends on what you are trying to accomplish and how it is currently set up.
Best would be to use a content delivery network for static images to ease the load of your web server.
You can serve from database or as resource file in file structure to your liking. If the images are static don't forget to add appropriate caching which for static content would be far future.
If you're rendering images I would definitely keep the images in the database to make it possible to access the images from any number of web servers.
If you want you can develop this further by keeping the images most recently used in memory or store on local filesystem so you don't have to get the file from the database every time.
web folder. also think about remote loading them from a cloud server like Amazon S3 to free up access to your own server
THe best option is to store your images on web folder, if you save them in DB, you will waste time retreiving them from DB because it takes more time
I am creating a site whose content is dynamic and has images in it.
What/How much performance hit will my DB (MSSQL) take if I save content/Images in DB?
I am just trying to understand what kind of problems I may run into.
I appreciate any responses.
Thanks!
If you keep content (e.g. images) outside of the database, you can let IIS serve this content directly without calling ASP.NET at all (and as a consequence, no database access is needed).
You can even put static content on a different server is you have huge load (like here on StackOverflow).
So if you need to scale in any way, keep static content outside of both ASP.NET and database.
In the company where I'm employed we are using a custom-made CMS.
It renders content and controls for a page dynamically. The content are stored in a table for all pages, (each page has one main content), and other tables store information regarding UserControls, path to it, and which properties should be set with which value via reflection.
The performance is good, even for lets say 10 dynamically created controls. Our biggest client's page has about 70k hits a day and there is no performance problem. The page renders really fast.
Storing the images in your database can also work.
Just keep in mind that you need to use server-side caching for your images (e.g. get them via a generic handler *.ashx and use chaching there) and hope that your imageurl gets recognized for clientside caching.
If you want to be sure, expose your images directly on a dedicated image application. (e.g. www.foobar.com is your URL, then you can create images.foobar.com and store all your images there)
If would definetly advise to store often used images there, like images for the layout, or userpictures (if you are using a forum, or some kind of web application that uses several pictures all the time). But there is nothing wrong with storing not often used pictures in the database (user related uploads et cetera).
If you store your images in DB, database size will increase and this will result in slower DB queries. Better store on other media and guide your DB to do the stuff for you.