How to publish generic file using web publish in Visual Studio? - asp.net

I am using Visual Web Developer 2010 Express (I am using VS for 10 years) and I publish a web site using web publish to Azure. I want to publish a generic file lets say a .dat file that users will download. How should I add it to project so that it is published and available to download by users. I tried adding to specific folder in project, setting build to content and always copy. I can see the folder created but when I type specific URL , i got generic file or folder not found error. If I put an xml file to same folder , I can see it with direct url.

Internet Information Service does not serve the files that it does not know about. Your .dat file is not supported by IIS by default so you have to add it manually.
Add following configuration to your web.config file.
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".dat" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
</configuration>

Related

Deployment of the ASP.NET website to Windows Server via FTP

I am trying to deploy my test website to the ftp server, yet I am having quite a few difficulties with it (as it is my very first time doing this).
Here is how the ftp's server folder setup looks like:
There is a main folder named www_root, which contains the following two folders app_data and data.
Here is a printscreen from a TotalCommander:
I was being told by the support people, that I need to copy all my data into the www_root folder.
Once I published my ASP.NET 5 MVC application via Visual Studio 2015 to a File System, I could see three folders:
My base index.html, together with css & javascript is located under wwwroot folder. Here is what the inside of wwwroot folder looks like:
When I copy the contents of my wwwroot folder inside www_root folder (under FTP) and I exclude web.config file, then my base webpage is loaded without a problem (but without server side logic...it's just a plain page with some HTML & CSS code).
Now the problem occured when I added web.config to that folder, then suddenly I received Error 500 when I tried to open my website. I believed that the problem was caused by the fact that web.config contained the following setup:
<configuration>
<system.webServer>
<handlers>
<add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="..\approot\web.cmd" arguments="" stdoutLogEnabled="false" stdoutLogFile="..\logs\stdout.log" startupTimeLimit="3600"></httpPlatform>
</system.webServer>
</configuration>
Here I could see that we are targeting \approot\web.cmd file. Therefore what I did was, that I copied my approot & logs folders (generated by Visual Studio) to the base folder under my FTP.
So in the end when I logged in to my FTP I had the following folders: approot, logs, www_root, where inside of www_root I had all my css, js, & index.html.
Nonetheless, when I reloaded my webpage, it still gave me the 403 - Forbidden: Access is denied..
How can I solve this problem? What am I doing wrong?
In the end, the problem was occurred by the fact, that my hosting server had folder named www_root, however my ASP.NET application automatically creates folder wwwrooot.
What I ended up doing is creating a script, which loops through all the files and replaces wwwroot with www_root.
That has solved the problem.

How do I access uploaded files on Microsoft Azure websites?

I wanted to upload some audio files to my azure [ASP.NET] website. I then came up with this idea: I created a WebAPI action responsible for uploading the audio files into an UploadedAudio folder that I created inside the Content folder (wich is a public folder, right?). Everything is working just fine in Debug mode.
After publishing to Azure, I can see that the files are persisted with paths like D:\home\site\wwwroot\Content\UploadedAudio\5ab46baa-ffa7-4b7f-bbb9-9d0c53fa0751.mp3, but I'm not able to play them like I can in Debug mode, because I get a NotFound error. Here is the URL that I use https://mywebsite.azurewebsites.net/Content/UploadedAudio/5ab46baa-ffa7-4b7f-bbb9-9d0c53fa0751.mp3. In Debug mode, http://locahost:port/Content/UploadedAudio/5ab46baa-ffa7-4b7f-bbb9-9d0c53fa0751.mp3 is working fine!
How can I access the uploaded audio files?
I hope that my problem is clear enough. If someone can help me with this...
Thanks.
Got it !! adding these lines to the web.config is the solution:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".mp3" mimeType="application/octet-stream" />
</staticContent>

Can't serve up files with custom file extension in ASP.NET despite mimetype declaration?

I'm working on an ASP.NET/MVC/Razor web site. I need to server up files with a "pdb" extension. The *.pdb files are plain ASCII text files. I tried adding the following declaration to my web.config file:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".pdb" mimeType="text/plain" />
</staticContent>
</system.webServer>
But I still get a 404 error whenever I try to load one of the files:
HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.
I found this SO post that talks about running a utility to register the version of .NET you are using, but I believe the context is that of installing a web site on to other serves, not just a simple publish scenario like mine:
"The page you are requesting cannot be served because of the extension configuration." error message
What am I doing wrong? Note this is happening when I run locally with IIS Express from Visual Studio 2013 Update 4.

Prevent overwriting of a file when deploying?

NOTE: This is for a Visual Studio Web Site Project and NOT a Web Application
I am using web deploy to push changes from my development machine to my staging server. I would like to push any files that are different to the staging server except for one particular file (lets call it myFile.whatever)
So far I have tried editing the C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe.config file to look like so:
<configuration>
<startup>
<supportedRuntime version="v2.0.50727" />
<supportedRuntime version="v4.0" />
</startup>
<rules> <------------ ADDED THIS NODE
<rule name="skipConfig" type="Microsoft.Web.Deployment.DeploymentSkipRuleHandler"
objectName="filePath" skipAction="Delete"
absolutePath="C:\inetpub\wwwroot\MyProject\myFile.whatever"/>
</rules>
</configuration>
But it is still overwriting the file in question on my staging server. I started by editing the msdeploy.exe.config on my dev machine and when that didn't work I updated the msdeploy.exe.config on my staging server as well, but again, still not working.
Am I going about this wrong? Any suggestions on preventing this file from being overwritten?
Since transforms are painful with web site projects you might be able to use this method: http://blogs.msdn.com/b/webdev/archive/2010/04/22/web-deployment-excluding-files-and-folders-via-the-web-application-s-project-file.aspx
As stated in the comments, what you would normally do is to have a base Web.config file, then one specific for debug and one specific for release. The debug or release portion would add/override the base one with things that are particular to this scenario. This way you can just upload both and everything will work fine.
To understand more about web.config transformation, please refer to: http://msdn.microsoft.com/en-us/library/dd465326(v=vs.110).aspx

Sharing .Net Web Configuration File Issue

I'm having some trouble with a current project. I have a Solution with 2 separate projects in it. The first is my Project that I am publishing, which has a web.config file. The second is a data access project, which only contains .cs files, and has an app.config file, as well as a Properties folder containing a Settings.settings file.
Like so:
Solution
DataProject
app.config
Settings.settings
Code.cs
PublishProject
Code Files
Web.config
My Problem is that I want to be able to edit the app.config file settings after the solution has been published, but the app.config file gets rolled into a DataProject.dll that sits in the bin folder in PublishProject. Because of this I cannot access the app.config file to edit it post-publishing.
I have tried to setup the app.config file as a linked file that just points to the Web.config file in the other project, but the issue there was that the Settings file does not get updated with the correct values from the app.config file unless you open the settings file in Visual Studio and allow it to reload. The values in the settings file are the ones that are being used throughout the application.
Right now are only workaround is to change out the configuration and re-publish the project.
In case anyone else runs into this problem, here is the workaround that I was able to use:
Create an xml file in the PublishProject, and convert the data in the app.config into individual xml tags like so:
<configuration>
<setting name="debug" serializeAs="String">
<value>False</value>
</setting>
</configuration>
becomes
<Properties>
<debug>True</debug>
</Properties>
Once you do this, you can call the following in your code, instead of using the value from the Settings.settings file.
XmlDocument doc = new XmlDocument();
String appPath = HttpContext.Current.Server.MapPath("~").ToString() + #"/App_Data/Properties.xml";
doc.Load(appPath);
debug = Convert.ToBoolean(doc.SelectSingleNode("Properties/debug").InnerText.ToString());
Note: that I put it in the App_Data folder of the finished project because that folder is not accessible via a browser by default.

Resources