I've been trying to reduce the amount of copying and pasting of content files across some of my projects and decided to go down the adding files as links from a central project.
The problem I have now is that the System.Web.Optimization.Bundle.AddFile(string virtualPath, bool throwIfNotExist = true) does not work as the file doesn't really exist in the directory I specified.
Does anyone have any pointers? Or maybe an alternative to linking content files?
Thanks.
I think you cannot access files outside of your web project with the virtual path system and It might hurt when you want to deploy your app.
I suggest to make a custom project for your static content with a custom domain: e.g. static.yourcompany.com and reference all this files from this domain. This also has the advantage that the browser does not have to add the cookies for authentication and tracking to these requests, which might be faster if you have a lot of traffic. You can also open your custom cdn (http://www.maxcdn.com/pricing/) or store the files in azure or amazon aws (which is more or less free for less files and traffic).
Another approach is to make some batch files to keep your content files synced.
Related
I'm developing a Web Application, and it is running as an Azure Web App. This application has a section in which a user can navigate a directory, and allows the user to open the files and browse sub-directories in said directory.
At the moment, the sub-directories and files are inside "~/Content/Documents", and I am browsing the directory's by using Directory.GetFiles() and Directory.GetDirectories(); functions which are provided by System.IO.
The files in question would be retrieved and downloaded several times a day, and there is no way to manually path one-by-one, seeing as there is a large quantity, and they are subject to change.
However, I has become inconvenient to store the files within the web directory. So my two questions are:
What Azure service can I use to store and retrieve my files?
and
Which of these services provides the ability to index/map a path, which would fit with my web-app?
Please note that the users do not have the ability to edit or otherwise upload any of the files, and there is therefor no need for the service to allow non-authenticated upload.
The newish Azure File Storage feature can be used to store files in Azure Storage and make them accessible via an SMB file share. This will allow for legacy application that require the use of a traditional file share for saving / retrieving files. This allows for easier integration into existing applications without needing to completely rewrite the file storage code.
https://azure.microsoft.com/en-us/blog/azure-file-storage-now-generally-available/
I have two web application in my solution. One of them is for managing the system and another is for clients.
I should publish them one by one in separated places (of course on a machine but in separated addresses for Example http://manager.com and http://clients.com)
My question here is that, can clients web application access the files that the other manager web application has (in its physical directory)? If not how can I approach this problem?
see this design to get more details for this problem :
Thanks!
What I usually do in a scenario like this, is store the files in a folder in the application that does the writing. Then I use IIS to create a virtual directory in the other application that points to the folder containing the files in the first application.
So in your case, you could have a folder "Files" in the manager.com website. Let's say the folder has this full path: D:\Websites\manager.com\Files You can then create a virtual directory in the clients.com website pointing to that path.
This has the advantage that you can code everything as if the folder exists in both applications.
If your applications placed on one machine - certainly can.
You should do only one thing - give permission to folder with files (Or permission to DB with files) to user that run your web application on web server (Usually IIS if you use MVC < 5)
It seems from your comment that you want to share uploaded files between multiple web project. You can store them in a common folder outside your web project folder.
For example, create a folder in
"C:\Temp\" say "SharedFiles".
The manager web application that receives the file from user (through upload) can store the files in this folder. The client web application can refer this location for file while reading.
You may have to give permission to the user (IIS_IUSRS) to access this folder.
I'm optimizing my ASP.net MVC 4 website. I'm currently using run time bundling to combine and minify my JavaScript and CSS content. I would like automate publishing of the minified content to a CDN (specifically Amazon Cloudfront) as they are created.
I am trying to determine the best strategy for integrating bundled files with a CDN. My specific questions are:
Are there any available libraries that would allow bundled files to
be saved to a CDN rather than my local web server?
Should static files be pulled from a CDN prior to bundling or should they be pulled from a local Web server prior to bundling?
Are there any mechanisms to enable CDN write control only from my web farm (and not the general public)?
I don't personally buy into the "USE CDN FOR EVERYTHING STATIC!!" mentality, so I refuse to worry about copying local scripts to a CDN as you described. Sure, the big libraries can be referenced from existing major CDNs (Yahoo, Microsoft, Google), but for local scripts, it's really not worth the hassle, IMO.
Following that line of thinking, I've grown very fond of SquishIt. There's no extra XML config or preinitialization necessary to use. Just include it in the master or layout file like so:
<%= Bundle.Css()
.Add("~/Content/Reset.less")
.Add("~/Content/Site.less")
.Add("~/Scripts/rcarousel/widget/css/rcarousel.css")
.Add("~/Scripts/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.css")
.Add("~/Content/Fonts/Karla/stylesheet.css")
.Render("~/Cache/Bundle.css") %>
<%= Bundle.JavaScript()
.Add("~/Scripts/jquery-1.7.2.js")
.Add("~/Scripts/jquery-ui-1.8.19.js")
.Add("~/Scripts/modernizr-2.5.3.js")
.Add("~/Scripts/rcarousel/widget/lib/jquery.ui.rcarousel.js")
.Add("~/Scripts/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.js")
.Add("~/Scripts/jquery.youtubelite.js")
.Render("~/Cache/Bundle.js") %>
Having said that, and more to your point:
1) I'm not aware of any bundling libraries that support automatic CDN deployment. The usual train of thought here is to have the CDN pull from your website directory and cache it. In this way, deployment is established via a pull mechanism, rather than a push. This article describes how to set up origin pull using CloudFront with a word press site. I'm sure the configuration is similar for ASP.NET.
2) Bundle from local copies. You probably reference the local copies in development already, so why add the CDN into the mix prior to go-live?
3) Most cloud storage systems (Amazon S3, Azure Storage, Rackspace Cloud Files) offer a way to publish files to the cloud that remain read-only to the public. This is API-dependent, so the method varies depending on your cloud storage provider.
After more research I came across the Squishit.S3 library which does exactly what I needed. Essentially it piggy-backs on squishit, enabling bundled files to be copied to an S3/Cloudfront bucket at runtime. Configuration is a breeze and because it uses Amazon's APIs, credentials are used to write to the CDN. If you already use Squishit it's just a matter of adding a couple of default configuration lines to your global.asax and the rest is taken care of for you
I have a web app where the administrator can create news, pdf documents and other stuff in his cms panel.
The problem is when the admin delete a new or something else the app deletes all the files related to that new, I mean the images, pdfs and other documents. Tha main problem is those files are stored in folders under the "news" folder and when the app deletes them the session is lost.
How can I do to have a file system without losing the session?
I'd like that file system within the app folder...
Impossible for us to store those folders outside the app and we don't want to use StateServer because of the performanne....
Any other solution?
Thanks
Your session is lost becasue IIS recompiles. The easiest solution in my opinion is to store your files outside the wwwroot.
Discussed on SO: ASP.NET restarts when a folder is created, renamed or deleted
[Update]
Example:
Let's stay your app is in c:\inetpub\wwwoot\virtualdir1
You make a work directory:
c:\inetpub\inetwork
Give the proper rights (read/write/etc) to the Asp.net user of your app pool and it should all work like a charm.
More info on setting the rights: What are all the user accounts for IIS/ASP.NET and how do they differ?
Store the path to the workdirectory in your web.config (you no not want to hardcode it)
Having those files within the app folder is a poor desgin. The session is probably lost as you are causing IIS to recycle due to the file system changes. It is much safer to not have your web application able to write to its own folder, doing so is a security risk.
Separate your document folder and web site folder. And give right permission your document folder.
I have an ASP.NET MVC website that works in tandem with a Windows Service that processes file uploads. For easy maintenance of the site, I'd like the log file for the Windows Service to be accessible (to me, only) via the website, so that I can hit http://myserver/logs/myservice to view the contents of the log file. How can I do that?
At a guess, I could either have the service write its log file in a "Logs" folder at the top level of the site, or I could leave it where it is and set up a virtual directory to point to it. Which of these is better - or is there another, better way?
Wherever the file is stored, I can see that there's going to be another problem. I tried out the first option (Logs folder in my website), but when I try to access the file via HTTP I get an error:
The process cannot access the file 'foo' because it is being used by another process.
Now, I know from experience that my service keeps the file locked for writing while it's running, but that I can still open the file in Notepad to view the current contents. (I'm surprised that IIS insists on write access, if that's what's happening).
How can I get around that? Do I really have to write a handler to read the file and serve it to the browser myself? Or can I fix this with configuration or somesuch?
PS. I'm using IIS7 if that helps.
Unfortunately I'm afraid you'll have to write a handler that will open the file, and return it to the client.
I've written an IIS Manager extension that displays server log files, and what I've noticed that even the simple
System.IO.File.OpenRead("")
can still run in the same problem, and return the same error.. It was kind of confusing.
In the end I used
System.IO.File.Open("", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
and I could easily open the file while the server was writing logs to it :)
I think the virtual directory is an "okay" solution, if you add the directory (application) with READ ONLY rights + perhaps "BROWSE directory" too (so you can see the folder contents rendered by the IIS).
(But once you do that, you should consider that you also anonymous access to that folder - unless you enable authentication, so watch out for "secret" contents of the logfiles that you might expose? just a thought.)
Another approach, I prefer myself, is to make a MVC/ASP.NET page that does the lookup in the folder by normal code, so that you 100% can filter whatever data is shown in the HTML.
You can open the files as TextStream's and in Read Only mode.
If it's a problem to gain access to the logfolder, I would use the virtual directory with READ ONLY access and then program something that renders the logfiles as HTML on my screen and with my detail levels. Perhaps even add some sort of "login" first. But it all depends on your security levels and contents of logfiles.
is this meaningfull to you? if not, please explain more, as I've been through this thought a few times already for similar situations.