I can't access code from subdirectories in F# - f#

I am trying to get my head around how F# code is organised.
I understand that in a folder or main directory - to access code from a different file, the file must be above it, and I can move code up or down using Alt+Up , Alt+Down - makes sense.
However, if I Have some code in a subdirectory - even if that subdirectory is above the code it does not appear to be able to access it. If the subdirectory is in a parent directory it seems to be Ok. I can't seem to find the rationale for that anywhere. Thoughts?

However, if I Have some code in a subdirectory - even if that subdirectory is above the code it does not appear to be able to access it.
This doesn't sound correct. All that matters is the order of the files in the project file, so if you have this in your .fsproj file:
<ItemGroup>
<Compile Include="MyFolder\MyFile.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
Then Program.fs can access things defined in MyFolder\MyFile.fs. If you are seeing something different, please share the details.

Related

comment code in MVC5 web.config in debug mode

When I deployed my app I had to add following code to my web.config file because otherwise the server won't display my .svg file
<system.webServer>
<staticContent>
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
</staticContent>
<system.webServer>
However, if I leave that bit of code in the file while I develop on my machine, it leads to weird errors (e.g., my machine doesn't load my .css file anymore). All works fine if I comment that out again while working locally.
But exactly that is a hastle, commenting/uncommenting that code always when developing resp. deploying.
So my two questions:
1) Is there a way to include code conditionally in the web.config, e.g., depending on if degug or release build, or if deploying?
2) Why is that code causing trouble on my local machine in the first place?
UPDATE: So Q1 is answered, but still looking for an answer to Q2! Can't accept an answer before that ...
In your web.config File you have an arrow that points to two other Files called Web.Release.config and Web.Debug.config there you can make such changes. There you can modify your web.config based on your Run Mode.
There is a very good Microsoft Article about it im pretty sure it will help you
https://msdn.microsoft.com/en-US/library/dd465326(VS.100).aspx

How do I protect a file from direct download?

I have a webshop im developing, and some of the products need to be downloadable files (e-books, images, mp3 etc.). I have the files stored in a subfolder in my project and just a reference to them in my DB.
I dont want anyone with a direct file link to be able to download them, i want to control this myself. The download should only be available through my shop - that is, my customer area where the user can see all the e-products they have purchased.
How do i protect the files on my disk from being downloaded except by my code?
There are several ways to prevent the IIS static file handler from serving out the files to a client.
1) Using section in configuration. You can use the hiddenSegments element to specify sub-segment paths that will not be served. Look at %windir%\system32\inetsrv\config\applicationhost.config for how this section is defined and used to prevent access to bin folder and other directories.
<configuration>
<system.webServer>
<security>
<requestFiltering>
<hiddenSegments>
<add segment="subdirectoryName" />
</hiddenSegments>
</requestFiltering>
</security>
</system.webServer>
</configuration>
2) If you're looking for a simpler "poor-mans" way of blocking static file handler from serving out files, you can make the files "hidden" (from a file system attribute perspective). The static file handler will not serve out hidden files.
The easy answer: Don't place these files inside your site, place them outside the root of your site.
You can configure IIS to not serve requests to this folder with request filtering:
I'm assuming these paths are not paths you wanted to serve?

When I deploy, the mht file does not get copied across

When I deploy my project the help file with the mht extension does not get copied across to the drop folder with the rest of the project.
Why is this, and how do I fix it?
I am using tfs 2010.
I do not know how the problem was caused in the first place, but I found the way to fix it is to edit the .prog file.
The <ItemGroup> was corrected as follows;
<Content Include="Views\Leaver\ConfirmSubmission.cshtml" />
<Content Include="Help\Help.mht" />
<!--<None Include="Help\Help.mht">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>-->
So I replaced the commented out code with the line above, ie <Content Include="Help\Help.mht" />
and now it works.

Visual Studio: How to override the default "Build Action" for certain extension types per project or solution?

I'm serving my asp.net mvc views from many assemblies and copying views to the main application on post-build event.
This works, however, I realized, that when I change something in view and just hit F5, changes are not included. What I have to do to see changes is to: save, build<- explicitly clicking, and then hit F5. However, it's pretty annoying solution.
I discovered that setting Build action to "Embedded Resource" on view solves the problem as well, however other devs may not remember that they have to do this after adding every view to the solution.
Is there a way to override the default build action for certain file extensions, such as: *.aspx, *.ascx in project or (better) in solution ?
What I've found is an ability to add this setting globally, per machine, but I do not want to do that (link: http://blog.andreloker.de/post/2010/07/02/Visual-Studio-default-build-action-for-non-default-file-types.aspx)
Any ideas ?
Consider the following project file outline:
<Project ToolsVersion="3.5" DefaultTargets="EmbedViews;Build" ...>
...
<Target Name="EmbedViews">
<ItemGroup>
<EmbeddedResource Include="Views\*\*.aspx" />
<EmbeddedResource Include="Views\*\*.ascx" />
</ItemGroup>
</Target>
</Project>
This will add all aspx and ascx files in Views\<subfolder> to your library as Embedded Resource. Notice that EmbedViews is added to DefaultTargets before Build - order is important here, I found out making that mistake myself :-)
Since editing all your project files to get this snippet in is cumbersome, you could make your own project template with this included.
Please let me know if this helped.
In case anyone wonders here - there is still no way to do that if you want it to work on current and future items.
In VS 2017 when adding new file when the catch-all rule is present (e.g. Content Include = "**.*ts") if you add a new file, it will add it's own line to
<ItemGroup> with it's own BuildAction, ignoring your predefined catch-all.

where to place the struts.xml file

I need to know...where we have to place the struts.xml file...Is there any possibilities of changing the location of struts.xml file
By default, it is looked for in the classpath's root level.
Place yours directly under WEB-INF/classes (or to a place where someone/something grabs it and puts it there, typically the root of a source folder, such as src/main/resources if you are using Maven).
Another option would be to have it packaged at the root level of a JAR in your WEB-INF/lib. A struts.xml in WEB-INF/classes gets precedence though. I have yet to come across an example where this option would make sense though.
If you have a simple dynamic web project, I recommend putting it under the src folder. This is because it simply works. You can create a classes folder underneath the WEB-INF folder and move it there as well.

Resources