I have an application that stores images uploaded by user. Those images goes to content/images/upload. Problem is that if i published without the skip extra files on destination, all user uploaded content gets deleted. Im pretty sure im doing it wrongly, which would be the best approach for this situation ?
im worried about losing user generated content this way misconfiguring an option in publish.
One approach I've used is to move the physical path of the "upload" older outside the application folder structure. I'd use an IIS virtual directory to mount the folder to the application. For example, if the folder structure currently looks like this:
c:\inetpub\
wwwroot\
content\
images\
upload\
You might change it to this:
c:\inetpub
upload\ <-- must be manually created on the web server
wwwroot\
content\
images\
You'd remove the upload folder from the web application in Visual Studio. Log into the webserver and create the folder under inetpub (could go anywhere, really). Then go into IIS manager and create a virtual directory called upload that points to the c:\inetpub\upload folder.
The upload folder is no longer part of the Visual Studio project so the "publish" feature won't touch it.
Related
I'm publishing over webDav to webserver; the site is both classic asp and new c# aspx.
Currently it is only two pages, but the majority of the time is spent uploading bin/roslyn.
The time of the files in bin/roslyn changes to the time of publish.
Is this upload nessecary every time; does the files really change?
I'm not asking if bin/roslyn can be removed.
Is there a way to just upload the changed files?
I'm uploading over 4G network, while it is not exactly slow, it's not wirespeed either.
I don't uplode the entire website; there are a lot of old .asp and images I haven't pulled to my workstation, so I don't delete the existing files first.
Copying all files to temporary location below for package/publish:
obj\Release\Package\PackageTmp.
Publishing folder /...
Publishing folder bin...
Publishing folder bin/roslyn...
Publishing folder xml...
Web App was published successfully file:///Y:/
I'm not sure how to get a list of all files, but I'll write a few names:
Microsoft.CodeAnalysis.VisualBasic.dll
Microsoft.CodeAnalysis.CSharp.dll
Microsoft.CodeAnalysis.dll
Microsoft.DiaSymReader.Native.amd64.dll
This is in descending size; already this is about 10MB.
I have not used webDav before, but it seems like work the same as ftp publish.
If you want to publish only part which have changed, there is two way:
use web deploy
publish to local file then chose only upload the part has changed
use web deploy
there is article of how to set up web deploy at microsoft docs
https://learn.microsoft.com/en-us/iis/install/installing-publishing-technologies/installing-and-configuring-web-deploy-on-iis-80-or-later
essentially install web deploy at iis, then when publishing in VS, chose web deploy
deploy to local folder then upload change part
in VS, publish to local folder, then manually upload file which have changed (if you use version control, who wouldn't, you should be able to tell which files has changed)
I have a webshop in ASP.MVC.
The solution consists of 2 projects - a web.frontend and a web.admin.
In web.admin, file upload is possible. These files should be accessible from the web.frontend to show in browser.
I have tried tons of different C# methods to various paths...
Please provide me a way to put shared files where the browser can access them too.
I've tried placing the files at the .sln root - but the browser gives me an error: Not allowed to load local resource.
So somehow, the files should be placed in the web.frontend wwwroot? from the web.admin project?
Your only choice here is using virtual directories. In full IIS, that's a pretty straight-forward affair. You simply add a virtual directory to the site in IIS and point it to the location on the filesystem to where these files are stored. Then, you reference the files using this virtual directory in your HTML. For example:
Foo
The same is required in development, but the procedure is a bit more circuitous with IIS Express, since there's no GUI management. To add a virtual directory to your project in IIS Express, you'll need to go to File > New > Web Site... in Visual Studio. Click the Browse... button, and then click on the Local IIS tab. Select the site for your project, and then click the icon at the top-right that looks like a yellow folder with a red asterisk. Type an alias name (this is what you'll use in your HTML) and then browse to the location of your files on the filesystem. Uncheck Create IIS application and then click OK. Then, click Cancel and Cancel again. You're not actually going to create a new website; it's just the only way to get to this area where you can add virtual directories. Rinse and repeat with your other project.
I have a VPS (Cloud Server) and I have Visual Studio, IIS, SQL... all those nice things installed. I am also sometimes doing development on this VPS.
This website is basically a simple file manager. When it loads, it lists files and folders that resides in the App_Data folder. This said, I am using the App_Data as my "root/home/topmost-directory" for the file manager.
The reason I am putting them in the App_Data folder is because I don't want users to just go like this: www.mywebsite.com/ROOT/[gets a list of files].
Instead, if they try to go: www.mywebsite.com/App_Data/[tries to get list], IIS will block them with a nice error (because IIS blocks access to that folder).
So, the website accesses the structure in the App_Data folder via code behind. This is how the website navigates. It can download, upload, move files around, rename... delete... everything right to/inside the App_Data folder.
The only problem is, this only works when I run the website in Visual Studio and run my tests, testing the website, debugging, etc. The moment I publish (via File System in Visual Studio) the website to the directory: "C:/inetpub/Sites/[WebsiteFolder]", and navigates to the website's URL, the website does not work any more. It loads, but it does not get the file structure in the App_Data folder any more, it cannot create new folders, cannot rename them...
This website works fine when I upload it via FTP to another webs space that is hosted somewhere else at another hosting company (which is shared hosting).
So I guess (my best guess) the IIS on my VPS does not allow this kind of access. And I have been trying to find settings on IIS somewhere that would/could allow this.
I have enabled directory browsing, but that's probably the only thing I can think of other than making sure the directory is accessible (readable/writable).
Do you perhaps know what else I can try?
Ohkay, so this was a very silly mistake - but that's how we learn!
The App_Data folder did not have any other files or folders inside of it.
And as we know, ASP.NET does not publish empty directories. This means those empty folders never existed once I published the website.
There are 3 ways to fix this that I know of at the moment:
If your solution has a publish profile (so that you can publish the site), you can right click the empty folder in Visual Studio, and say Publish [FolderName] eg:
You can just create an empty file in that directory, and publish your whole website again. Because the folder is not empty any more, it publishes with the rest of the website.
Just manually create the folder on your hosting space.
Thanx for everyone's input!
Greatly appreciated!
I am developing a desktop application using C# winforms. I am creating some files and folders on the directory that my application runs at. I am deploying the application by using the click once approach. My problem is that everytime i update my application it creates a new root folder to run at. And i won't be able to use those files anymore. Any workarounds for that? I am thinkin of creating a folder at "C:\MyCompany\MyApplication" but then it will be easily reachable and breakable. I will be happy to hear any other advises or knowledges that will favor me :)
You should store the files and folders in the user's Application Data folder. You can get the path to this folder with this statement:
string appDataPath = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
You should then create a folder in that path for your application and store everything there.
There are of course other solutions, but the point is that you should not use the application folder, since this will indeed change everytime you publish, and it is bad practice for several other reasons (data backup, etc.).
I'm developing a Web application that uses a couple XML files to store data. I have their Build Action set to Content, and on install the files are copied successfully to the Applications Virtual Directory:
C:\inetpub\wwwroot\ApplicationName\
The problem I'm having is that writing to these XML files (in order to save settings and things like that) causes a lot of write permissions issues. Therefore to get around it, I'm trying to copy these files from the virtual directory they're installed to to a new directory under the C drive, using the following PostBuildEvent in the Web Deployment Project:
xcopy "$(TargetDir)*.xml" "C:\CompanyName\ApplicationName\" /y
However, this does nothing. I'm not sure if this is because PostBuildEvents in the installer are not actually fired on install, but only on building the installer, or if TargetDir represents the bin directory:
C:\inetpub\wwwroot\ApplicationName\bin\
instead of the root application virtual directory:
C:\inetpub\wwwroot\ApplicationName\
Does anyone have any ideas? Has anyone dealt with this sort of thing before? I'm really stumped on this one.
Update:
I included a PostBuildEvent that should give full permissions to all users:
icacls "$(TargetDir)" /grant Users:F
But it doesn't seem to have resolved the problem.
I'm also unsure where exactly $(TargetDir) if pointing to, if it would be ..\ApplicationName\ or ..\ApplicationName\bin\
All you have to do is give full permissions to the user under whose context the Web Application Pool runs.
You can find this user by starting IIS manager and look at the Application Pools and Identity column
Something like
cacls C:\inetpub\wwwroot\ApplicationName /G Users:F
will give all permissions to this subdirectory to all users on the computer, If you are running under ApplicationPoolIndentity refer here
Turns out there's a much easier way to do what I was trying to do.
Instead of using PostBuildEvents to create a new directory structure and move files there, I added the new directory structure into
InstallerProject > View > File System
after which I located the Content Files from SomeProject entry in my installer project, and changed the Folder value to the newly specified directory structure, in this case
C:\CompanyName\ApplicationName\
This seems to work fine, I'm now able to access these files freely as I originally intended.