MVC web.config compilation debug=true - a manual change needed? - asp.net-mvc

When one creates a MVC project using the the built-in templates (File -> new Project etc) the web.config reads
<compilation debug="true" targetFramework="4.5" />
Inside the Web.Release.config I see this transform
<compilation xdt:Transform="RemoveAttributes(debug)" />
so I was assuming that when I build in Release mode the debug="true" would disappear. However I am not seeing this.
Is the transform only applied when publishing the website? I've seen websites deployed by drag & drop, with the Web.config copied over from the root (with debug="true" included).
I'd just like to check, if deploying via drag & drop do you have to remove this attribute manually? Or am I missing something?

Preferred would be to publish your web-site (different to F5 or drag and drop) so to update\transform the web.config ...
Disable debug mode
Depends on build configuration rather than destination environment, the debug attribute is for the Release build specifically when you typically want debugging disabled regardless of which environment you are deploying to.
Visual Studio project templates will create a Web.Release.config transform file with code that removes the debug attribute from the compilation element.
Below the default Web.Release.config: (with some sample transformation code that is commented out, it includes code in the compilation element that removes the debug attribute:)
<?xml version="1.0" encoding="utf-8"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>

Related

How to disable Tracing within a MVC Asp.Net application using Trace.WriteLine and Glimpse?

I use MVC3/ASP.NET 4.5, and use Trace.WriteLine("") type statements in my application which show up in my Glimpse Panel.
However how can I disable Tracing, say when I go into Production. I thought it was:
<system.web>
<trace enabled="false" />
But this does not work. The tracing comments still faithfully appear in Glimpse.
Unfortunately that trigger is focused on system web's tracing and not Glimpse. We could change things to adhere to that config point, but it doesn't currently.
Hence the following is what you want in you web.config:
<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
<inspectors>
<ignoredTypes>
<add type="Glimpse.Core.Inspector.TraceInspector, Glimpse.Core" />
</ignoredTypes>
</inspectors>
</glimpse>
And if you want the tab do disappear as well, you will want this:
<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
<tabs>
<ignoredTypes>
<add type="Glimpse.Core.Tab.Trace, Glimpse.Core" />
</ignoredTypes>
</tabs>
<inspectors>
<ignoredTypes>
<add type="Glimpse.Core.Inspector.TraceInspector, Glimpse.Core" />
</ignoredTypes>
</inspectors>
</glimpse>

Orchard CMS 1.7 Custom Theme images not loading

I had started creating a new theme while using v1.6.1.
Things were not going well with a custom module creation so I decided to start from scratch. This time I am using the source from V1.7
I copied my custom theme folder, pasted it into the themes folder of the new 1.7 project and ran the site. I could see the theme in my dashboard so I set it to the current theme.
Now when I view my site NONE of the images are loading. The style sheets are loading, though none of the images - either from the style sheet or from any views - are loading.
My images are in myTheme/content/images - which as I understand it is how 1.6.1 required things to be laid out.
My content folder has a web.config as does my images folder. It's the same config used in 1.6.1 so I'm wondering if something has changed.
In one of my theme views I have the following code - this worked in 1.6.1:
<img src="#Url.Content(Html.ThemePath(WorkContext.CurrentTheme,"/Content/Images/phoneBullet.png"))" alt="T:" />
If I output this to my front-end I get:
~/Themes/PerformanceAbrasives/Content/Images/phoneBullet.png
This tells me things appear to be in the correct place - though I'm wondering if my web.config is now out of date?
I have this - there is a copy in content and a copy in images:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<httpHandlers>
<!-- iis6 - for any request in this location, return via managed static file handler -->
<add path="*" verb="*" type="System.Web.StaticFileHandler" />
</httpHandlers>
</system.web>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
</staticContent>
<handlers accessPolicy="Script,Read">
<!--
iis7 - for any request to a file exists on disk, return it via native http module.
accessPolicy 'Script' is to allow for a managed 404 page.
-->
<add name="StaticFile" path="*" verb="*" modules="StaticFileModule" preCondition="integratedMode" resourceType="File" requireAccess="Read" />
</handlers>
</system.webServer>
</configuration>
Any pointers?
UPDATE
Ok... so if I set my project to use Visual Studios internal development server then all is well - if I tell it to use Local IIS Web server - use IIS Express (http://localhost:30333/) - then it doesn't work...
UPDATE 2
Ok - now running from IIS 7 and images do not load... stylesheets seem ok, but images are not.. grrr
any ideas so I don't run into this problem when I deploy?
Ok - I figured it....
You only need the web.config in my Content directory - not in both content AND images

Page Inspector Runtime must be registred in root web.config. Warning

In VS 2012 update 1,
I am getting a "Page Inspector Runtime must be registred in root web.config" Warning, when running the page inspector.
Can anyone assist me in what I have to put in the root web.config to fix this . Or some other solution.
Thanks
I realize this is an old question, but since it comes up on a search for the same issue which is still relevant to VS 2019, I thought I'd provide the actual answer:
The error mentioned here is referring to the registration of a file that is in GAC that needs to happen in the machine-level web.config. Not, as the other answers mentioned, in the project's web.config file.
The machine-level web.config file is located (for .net 4+, which I'm assuming is all anyone is using right now) at c:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config
And here is what you'll need to add:
<configuration>
..
<system.web>
...
<compilation>
<assemblies>
...
<add assembly="Microsoft.VisualStudio.Web.PageInspector.Loader, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</assemblies>
</compilation>
</system.web>
</configuration>
There's obviously a lot more in your machine-level web.config file - I'm just showing it as above so you see the hierarchy it needs to be in.
Normally this is added by the VS installer. But there are circumstances in which the installer fails to add it or even removes it..
To generate the metadata that is required for some of its features, Page Inspector must instrument the project by adding the following setting to the element in the Web.config file. You can use Page Inspector even if this setting is disabled or it is missing. However, some features like the source selection mapping will not work under these conditions.
Web.config
<add key="VisualStudioDesignTime:Enabled" value="true" />
Add to 'web.config' the key/value suggested by #Vicky_Raj_Sharma above and the "PageInspector:ServerCodeMappingSupport" under , like this:
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<!-- Keys above came with Hot Towel SPA template for VS2012 -->
<!-- Keys below where manually added -->
<add key="VisualStudioDesignTime:Enabled" value="true" />
<add key="PageInspector:ServerCodeMappingSupport" value="Enabled"/>
</appSettings>
When browsing the page (Browse with menu) from within VS it will show the page in your preferred browser.
Still haven´t figured out how to run this directly on IIS8 though...

Why don't my Html Helpers have intellisense?

I can't get intellisense for my own html helpers. My CustomHtmlHelpers.cs looks like this:
using System.Web.Mvc;
using System.Text;
using System.Web;
namespace laget.Web.Helpers
{
public static class CustomHtmlHelpers
{
//MY HELPERS
}
}
and in my Web.config:
<pages>
<namespaces>
<add namespace="laget.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages"/>
<add namespace="System.Web.Helpers" />
</namespaces>
</pages>
If I put <#using laget.Web.Helpers> in my view, I get the intellisense issue fixed.
Should it not be enough with the code in Web.config?
Sometimes it doesn't seem to work right away. Try closing the .cshtml file, and re-opening it. Then if that doesn't work, try restarting Visual Studio. Also make sure you actually compiled your project, intellisense won't work with non-compiled helpers.
I'm pretty sure that you're not editing the correct Web.config file.
You need to add your namespace to the one in your Views directory.
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="laget.Web.Helpers" />
</namespaces>
</pages>
</system.web.webPages.razor>
You actually don't need to restart Visual Studio in most cases. All you need to do is close the .cshtml file and reopen it!
It needs it on the local page. I'm pretty sure this has to do with Namespace resolution. It isn't exactly sure what you are referring to without the local using statement.
I ran into this today as well. Sometimes just closing the Razor view's window in Visual Studio and re-opening it will do the trick without having to do a full Visual Studio restart.
I tried to solve an issue like this one yesterday. I had e pre-compiled dll (project name ie: MyHtmlHelpers) containing helpers and lot of other classes.
I had the assembly referenced in the web project and the all "standard"-helpers showed up in intellisense but, even though I added the namespace to both web.config in the root and in the views-folder nothing worked. When running the project helpers works, but not in intellisense.
I added a new class and wrote a new html helper inside the web project, added the namespace to web.config. And that worked.
After some hours add tried my last card, adding the MyHtmlHelpers-project to the same solution as my webproject. That did the trick. I diden't change anything in the configs just added the project to the same solution and changed the reference to point at the project insted of the compiled dll.
Isen't that strange? A VS-bug?
I found that i was adding the reference to the wrong web.config. It's not the main config but the web.config in the views directory...
So now I will show you the steps
1.Create or open an existing class library project (if you open an existing one be sure to remove the MVC5 nuget package)
2.Add the MVC (5.0) nuget package (
right click project in solution explorer -> Manage NuGet Packages -> search for MVC and install “Microsoft ASP.NET MVC”)
3.Close any and all open .cshtml files
4.Right click project -> Properties -> Build -> change Output path to your project “bin/”
5.Add the following minimal Web.config to the root of your class library project
( the web config file is solely needed for intellisense. Configuration (via Web.config)
should be done in the WebApplication hosting your ClassLibrary assembly)
6.Clean and Build the solution.
7.Open cshtml file and try now :)
I found that if it still doesn't work, you may need to go to the properties of the custom class and change the build action from "content" to "compile". That resolved it for me.
I try all of this solutions, one more thing which i didnt find is that in root web.config i must change webpages:Version from 2.0.0.0 to 3.0.0.0.
Open and close all .cshtml files and it's worked.
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />

MvcSiteMap Provider Setup Problems

In relation to this post I'm using the MvcSiteMap provider. I can't seem to get it to work. What I'm doing is opening the project made available by the download, compiling it, then taking the MvcSiteMap.Core.dll generated by the build, placing it in my Dependencies folder in my MVC project, and then right-clicking on references and hitting "Add Reference". From here I'm just trying to use it in my masterpage but intellisense isn't picking it up, and trying to build with it isn't working either.
I'm trying to do <%=Html.SiteMapPath()%> without any luck. Any ideas?
Have you add <add namespace="name of the mvcsitemap package"> to yours web.config (under following xpath: /configuration/system.web/pages/namespace)?
Here is an example from the project home page: http://mvcsitemap.codeplex.com/
<pages>
<controls>
<! -- ... -->
</controls>
<namespaces>
<! -- ... -->
<add namespace="MvcSiteMap.Core.Helpers"/>
</namespaces>
</pages>

Resources