My Setting
I'm creating a base mvc project for a number of other mvc projects where all the error handling and basic user validation is located so that I don't have to duplicate the boilerplate code in all of the other projects. With the help of my favorite dependency injection container (go, go SimpleInjector) I was able to put my ErrorController within the base project and have it being used by the other projects. The same goes for the custom user validation attribute I created.
I'm using ASP.NET MVC4 targetting .NET4.0 with the following layout:
MvcBase
+- Controllers
+- ErrorController.cs // Common error controller
+- Filters
+- AuthenticateUserAttribute.cs
+- Application.cs // Base class for all MVC applications
+- Web.config // Base configuration (*)
MvcProject1
+- Views
+- Error
+- Index.cshtml
+- Web.config
MvcProject2
+- Views
+- Error
+- Index.cshtml
+- Web.config
The Question
I know that the Web.configs inherit from parent directories but is there a way to explicitly state the base config file such a configuration should inherit from? In my case it would be great to be able to reference the (*) Web.config, which is located at the same hierarchical level as the projects containing the other Web.configs. My use case is that I want to store some information in the basic Web.config that is the same in all other projects (e.g. configuration for error emails) that I don't want to duplicate in the other projects to keep the overall architecture as DRY as possible.
Any help would be appreciated ...
You can sort of achieve what you're looking for via the configSource attribute. You add that attribute to a section of your web.config with a path to another config file that holds those settings, e.g.:
Web.config
<connectionStrings configSource="bin/ConnectionStrings.config"></connectionStrings>
ConnectionStrings.config
<connectionStrings>
<add ... />
</connectionsStrings>
Then, you can use the `Add... > Existing File" option to add these configs to other projects. After you select the config file you want to add, click the arrow next to the "Add" button and choose "Add Link" instead. This will cause Visual Studio to simply create a link to the existing file instead of copying it into the project. Then, any changes will propogate automatically to any project that has linked to the file.
Related
I was recently asked to contribute in a latex project which is already relatively large. The main project is in one folder lets call it "project". There ist also another folder called "style", which includes some .cls files and some images.
I already found out, how to download submodules recursively via git and now I have a project structure like this:
parent_folder
|
+- project
|
+- project.tex
+- style
|
+- stylesheet.cls
In project, there is a file project.tex which uses stylesheet.cls like this:
\documentclass[a4paper,11pt]{stylesheet}
When I try to compile project.tex I get an error:
Missing input file: 'stylesheet.cls'
I tried using \documentclass[a4paper,11pt]{style/stylesheet}, but the same error occures.
Has anybody an idea how to fix this, whithout changing the whole project structure?
Is there something like a latex-makefile? I'm quite new to latex, sorry if I'm asking stupid questions...
We're using maven-3.3.9 with maven-war-plugin to generate my final war. We were having problems with out static files when they were changed because browser was using the cached version.
So we decided not to use query string version attribute after referecing those static files. Our choice was to generate our static files directories overriden the way the maven-war-plugin states in Adding and Filtering External Web Resources docs, section Overriding the default destination directory.
Here's how we done it:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<webResources>
<webResource>
<directory>src/main/webapp/WEB-INF/resources</directory>
<targetPath>WEB-INF/resources/${parsedVersion.majorVersion}${parsedVersion.minorVersion}${parsedVersion.incrementalVersion}${buildNumber}</targetPath>
<filtering>true</filtering>
</webResource>
</webResources>
</configuration>
</plugin>
We're also using another plugins to get the project version parsed and number revision also, but they're not important to this question.
The problem is that the static files directories are created correctly as we expected but its contents are also created in the regular way like we're not using webResources instructions, so I get my resources contents dir twice. I get resources dir with the dir I want and all dirs inside of this second dir are also in resources dir as sibblings of it. How can I generate the resource dir as it is doing now and not duplicating its contents?
My final output is something like below:
|--- resources
|--- js
|--- css
|--- fonts
|--- js
|--- myoverridendir
|--- js
|--- css
|--- fonts
|--- js
Because the same folder is coming from two resource directories
Through src/main/webapp as it is warSourceDirectory
It is specified as a resource in webResources
As you want only one copy, the one coming from webResources, the one coming from src/main/webapp need to be excluded. It can be done using <warSourceExcludes> tag.
For example, let us say js is one such folder inside src/main/webapp folder. It can be excluded using <warSourceExcludes>js/</warSourceExcludes>
So I've recently started with ASP.NET MVC 4. I'm using the razor engine.
My question is concerning the view files, with suffix cshtml. It seems to me that these are precompiled into *.cs files by razor which in turn are then compiled into MSIL. (A pattern that is familiar from my days as a JSP developer.) One reason why I am making this assumption is that if I enter some invalid c# code into the cshtml file I get a compilation error displayed like this:
Line 34: public class _Page_Views_BaseDataAdmin_Index_cshtml : ...
And line 34 is not indicative of where the error is in the cshtml file, just as the class _Page_Views_BaseDataAdmin_Index_cshtml seems to refer to a regular .net class not the view file.
So my question is: Where do I find the cs file? Specifically, in the example above, "_Page_Views_BaseDataAdmin_Index_cshtml.cs"? Maybe I need to add some config to tell MVC to keep this .cs file on disk, if so, how do I do this?
Thanks!
A quick tip to find the generated files is to add this to your .cshtml file.
This will show you immediately the full path
<div>This file is compiled to #this.GetType().Assembly.CodeBase</div>
You can find the compiled views in your Temporary ASP.NET Files folder.
First find the .compiled file that corresponds to your view (ex: home.cshtml):
home.cshtml.a8d08dba.compiled
This file contains the assembly name: assembly="App_Web_hkc53urb"
Your .cs file will be the assembly name concatenated with a number: App_Web_hkc53urb.1.cs
An easier approach might be to use Windows search for your view name in the temp ASP.NET directory.
I am using JSR 303 Bean validation in my JSF 2.0 web application and it works fine with annotations. Now I would like to ignore annotations and configure validation rules using the validation.xml file, so this is what I did (I am using an eclipse dynamic web project) :
Added validation.xml under WebContent/META-INF/validation.xml
<?xml version="1.0" encoding="UTF-8"?>
<validation-config
xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration validation-configuration-1.0.xsd"
>
<constraint-mapping>META-INF/validation/constraint-mapping.xml</constraint-mapping>
</validation-config>
Then created the file constraint-mapping.xml under WebContent/META-INF/validation/constraint-mapping.xml
<constraint-mappings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.0.xsd"
xmlns="http://jboss.org/xml/ns/javax/validation/mapping">
<bean class="my.full.path.ValidationMB" ignore-annotations="true">
</bean>
</constraint-mappings>
Having these configurations in place, I suppose the annotations in my bean class ValidationMB shall be ignored, BUT this is not happening!, which makes me assume that the validation.xml file is not being loaded.
any ideas? thanks.
Environment:
Apache Tomcat 7.0.23
javax.faces-2.1.4.jar
hibernate-validator-4.2.0.Final.jar
hibernate-validator-annotation-processor-4.2.0.Final.jar
validation-api-1.0.0.GA.jar
slf4j-api-1.6.1.jar
From the spec: section 4.4.6. XML Configuration: META-INF/validation.xml
Unless explicitly ignored by calling
Configuration.ignoreXMLConfiguration(), a Configuration takes into
account the configuration available in META-INF/validation.xml. This
configuration file is optional but can be used by applications to
refine some of the Bean Validation behavior. If more than one
META-INF/validation.xml file is found in the classpath, a
ValidationException is raised.
To solve my problem I had to create a META-INF folder under the project src folder, which ends in the WEB-INF/classes/META-INF.
The structure of the web application is:
ROOT
|_META-INF -- don't put validation.xml here
|_WEB-INF
|__ classes
|_META-INF
|__validation.xml
But I think that if I pack my web application in a jar file and reuse it in another project It may not work, I will let you know later once I do it.
Try to put your validation.xml directly into the WEB-INF/ directory.
I stumbled across this while looking for something else but wanted to clarify to the OP what is happening. You do in fact need the file to exist at META-INF/validation.xml; however, that is relative to the classpath which is why it worked when you put it under WEB-INF/classes/META-INF/validation.xml.
The cleaner approach is to let the file be put there for you. Your Eclipse project should already be outputting whatever is in your source directory to WEB-INF/classes somehow for you or nothing would be running. But sometimes there are filters on what it outputs so it might excluding something. You might want to check your src dirs and make sure they don't have exclusions.
Just as an example, if you had a Maven war project, all of your java sources would go in src/main/java and the generated classes would end up in the WEB-INF/classes directory. The equivalent happens for src/main/resources which contains non-source files. When I want *.xml, *.properties, etc. to end up in WEB-INF/classes I put them in src/main/resources. For your example I would have a src/main/resources/META-INF/validation.xml file.
Hope this helps anyone else who comes across this and is confused.
I am using Subsonic MVC Template from this project.
Here is a folder named [Code Template] which contains the .tt files for generating views and controllers. But that is giving me error
"MvcTextTemplateHost not found"
I want to generate the create/edit/list pages based on the tables generated by subsonic. How can I do that?
what you want is this:
http://github.com/subsonic/SubSonic-3.0/downloads
1 add subsonic dll to bin folder
2 add reference to that DLL
3 add a connection string to your web.config or app.config
add the connection string name to your ttinclude file
drag files into your models folder
you are then ready to go
http://subsonicproject.com/docs/The_5_Minute_Demo
brilliant up and running in like 10 mins