Namespace removed in web.config not removed in a page with master - asp.net

I have defined this in the web.config of a subdirectory
<namespaces>
<remove namespace="App"/>
<add namespace="Tom"/>
</namespaces>
App is imported in the parent web.config file, Tom and App have classes with the same names.
To avoid errors resulting from ambiguous class names I removed the App namespace from the sub-directory where the Tom namespace is used.
However the namespace App is still imported on content pages that have a master page outside the Tom directory. This causes the aforementioned errors.
Here is my dir structure
-Root Directory
--Default.master
--web.config (App is added in web.config)
--Tom Sub-diretory
---web.config (App is removed in web.config)
---Content page that uses Default.master (Here is the problem)
---Page without master (Works OK)
Any solutions?

Suppose you have the following in the root web.config:
<namespaces>
<add namespace="App" />
<add namespace="Tom" />
</namespaces>
And in your sub web.config:
<namespaces>
<remove namespace="App" />
<add namespace="Tom" />
</namespaces>
There will be no problem to use the class in .aspx pages in the sub-folder even if they derive from a master page in the root folder but you won't be able to use it in the master page. In the root master page you will need to fully qualify the type: <%= App.DuplicateType %> or <%= Tom.DuplicateType %>.

What about explicitly prefix the usages with the namespace? That should always work.

Related

RadControl disappear and unrecognized tag prefix

i need to enhance the application which developed by other colleagues, the source code located at share folder such as \10.1.1.1\App1
and i had map the share folder as network drive such as T: drive
my colleagues can open the apps by VS and work properly, but when i open it by VS2010, it cannot display the RadControl in Toolbox, display unrecognized tag prefix error message and cannot reference telerik function in code behind.
i had tried many methods that found on forum and website but doesn't work. e.g.
Using Caspol.exe to grant .NET applications rights to a remote ...
Caspol.exe –m –ag 1.2 –url file://\10.1.1.13/App1/* FullTrust
Caspol.exe –m –ag 1.2 –url file://\T:/* FullTrust
Add reference to web.config
Remove dll from bin folder
refer Telerik.Web.UI assembly and register the tagprefix in the web.config or directly into the page:
<system.web>
<compilation debug="false" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5.1" />
<pages>
<controls>
<add tagPrefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI" />
</controls>
</pages>
or in the aspx page:
<%# Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

VirtualPathProvider doesn't (quite) work in production on IIS 7.5

I have been working on a project that has common bits of functionality, specifically I wanted to share the master file and related images/js/etc. To that end, the master page and its dependent files are all wrapped into a "global" DLL that is utilized by all "subprojects". This all worked great in development, but deployment yielded a surprise which seems to catch a lot of people off guard: VirtualPathProvider doesn't work when precompiled.
Now thanks to this blog post containing a workaround I was able to give another attempt at getting it to work. Regretfully, it still doesn't.
I opted to get rid of my Global.asax implementation and went with the blog post's AppInitialize approach:
public static class AppStart
{
public static void AppInitialize()
{
HostingEnvironment hostingEnvironmentInstance = (HostingEnvironment)typeof(HostingEnvironment).InvokeMember("_theHostingEnvironment", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField, null, null, null);
MethodInfo mi = typeof(HostingEnvironment).GetMethod("RegisterVirtualPathProviderInternal", BindingFlags.NonPublic | BindingFlags.Static);
mi.Invoke(hostingEnvironmentInstance, new object[] { new MasterPageProvider() });
}
}
Since the actual provider works in debug, I won't include it. If you would like to see it, don't hesitate to ask. Just wanted to keep the question as short as possible.
The interesting aspect to this whole situation is that production yields no errors about not being able to find the master page. To me, this means the provider is working, but for whatever reason the rest of the resources (js/css/etc) aren't being retrieved from the assembly properly.
So my question comes down to this: what are the reasons that this solution would work great in development, but not in production on IIS 7.5?
UPDATE 11/20/2011
Tried out David Ebbo's suggestion and had no results unfortunately. My web config looks something like this now:
<configuration>
<connectionStrings>
<clear />
<!-- ... -->
</connectionStrings>
<system.web>
<pages>
<controls>
<!-- ... -->
</controls>
</pages>
<compilation debug="true" targetFramework="4.0" />
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
UPDATE 11/21/2011
Just to verify my suspicion that the VirtualPathProvider was actually working, I commented out the third line (mi.Invoke(....) and redeployed the site. As I suspected, it now breaks due to not being able to find the MasterPage file. This issue appears to be related to only static files being delivered through the VPP.
IIS 7.5 will handle the static files itself. You need to put a line for each static file you want it to ignore in your web.config file to make them get routed through your VPP. See below for examples.
<system.webServer>
<handlers>
<add name="Images" path="*.png" verb="GET,HEAD,POST" type="System.Web.StaticFileHandler" modules="ManagedPipelineHandler" resourceType="Unspecified" />
<add name="Stylesheets" path="*.css" verb="GET,HEAD,POST" type="System.Web.StaticFileHandler" modules="ManagedPipelineHandler" resourceType="Unspecified" />
</handlers>
</system.webServer>
Maybe the problem is that requests for static files are not going through ASP.NET by default in IIS.
Try whether turning on runAllManagedModulesForAllRequests in web.config helps. e.g.
<modules runAllManagedModulesForAllRequests="true" />
Take a look at this post. It explains how to get static files through a virtual path provider in IIS 7. I believe this will solve your problem.

Telerik namespace not found in deployed MVC3 application

I have just deployed a new MVC3 application, and after some efforts on my hosting provider's side, MVC3 seems to be running OK, but now I get the following compilation error before anything on the site loads:
CS0246: The type or namespace name 'Telerik' could not be found (are you missing a using directive or an assembly reference?)
This occurs in web.config on the following line:
<add namespace="Telerik.Web.Mvc.UI" />
I know the DLL is present in the bin folder on the host, so I'm a bit lost as to what else could be wrong.
If you are using Razor this line:
<add namespace="Telerik.Web.Mvc.UI" />
must occur in ~/Views/web.config and not in ~/web.config. Could this be your case?
Like this:
<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="Telerik.Web.Mvc.UI" />
</namespaces>
</pages>
</system.web.webPages.razor>
http://www.telerik.com/community/forums/aspnet-mvc/general/issue-with-telerik-mvc3-razor-content-appearing-at-the-top.aspx
Read the reply by Mike Kidder. Sorry for linking another forum, I know that's annoying but I'd rather give credit where due.
Two big takeaways when converting to Razor syntax:
1) Use #( .... ) when outputting html, not #{ .... ;}
- wrap the code for Telerik controls in parentheses, not brackets
- using brackets, you're essentially telling Razor to execute a method. You won't get any output
2) Remove the ".Render()" method for any Telerik controls. Not used in Razor.
You have to set Copy Local to true for the assemblies you have referenced. In your case expand References, select the assembly, press F4 to open the properties and set Copy Local to true. The assembly most probably is installed in the GAC so when you add a reference to it by default Copy Local is false.
it might be in the bin folder but, since you didn't mention this, did you actually add reference to the file in the project? after adding the reference to the dll, it should build correctly

asp.net application moved - namespace not found

I had an installation of Umbraco in a subdirectory of wwwroot.
Everything worked well.
Now I moved all the files and folders of the Umbraco installation from the subdirectory to the wwwroot.
When I try to load the backend I get an error:
CS0246: The type or namespace name
'UmbracoMembership' could not be found
(are you missing a using directive or
an assembly reference?)
Now UmbracoMembership is a class of a custom usercontrol, which resides in the Membership.dll file which is in the bin folder.
Before the move everything worked. I'm guessing this has something to do with where asp.net is looking for the assemblies (and not an Umbraco specific issue), but I have no idea where and how to fix this.
Thank you!
-Elad
Check if you need to append namespace definition in your web.config. These will be applied to all pages.
<configuration>
<system.web>
<pages>
<namespaces>
<add namespace="MyNamespace" />
</namespaces>
</pages>
</system.web>
</configuration>

Mapping classic asp pages to .net in IIS

I'm trying to map requests for classic asp pages to be handled by .net, so that it runs through a custom httpmodule.
In IIS I have remapped asp requests to aspnet_isapi.dll - I'm sure I've done this bit right
Now in my test app I am getting this error:
Server Error in '/TestASPRedirect' Application.
--------------------------------------------------------------------------------
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.asp' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /testaspredirect/test.asp
Searching online for this error shows a load of people having problems with cassini, but this is not really relevant, I am testing this on both IIS 5.1 on XP dev machine, and have tested on IIS6 also getting the same error.
I have followed instructions for adding and registering a httphandler (see http://support.microsoft.com/default.aspx?scid=kb;en-us;Q308001), but I don't know what to put in the ProcessRequest routine to ensure the request gets passed on. What is the default .net httphandler, can I just map to this in web.config?: so something like:
<httpHandlers>
<add verb="*" path="*.asp" type="standard.nethttphandler"/>
</httpHandlers>
How do I tell asp.net that it needs to pass ASP requests on and not block?
Actually you are only one step far from the success. Adding following section to your Local website(or virtual directory) web.config file:
<configuration>
...
<system.web>
<compilation>
<buildProviders>
<add extension=".asp" type="System.Web.Compilation.PageBuildProvider"/>
</buildProviders>
</compilation>
<httpHandlers>
<add path="*.asp" verb="*" type="System.Web.UI.PageHandlerFactory" validate="true"/>
</httpHandlers>
</system.web>
It looks like the .asp extension is mapped to the HttpForbiddenHandler.
If you're using ASP.NET 1.1 then open the following file:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\CONFIG\machine.config
If you're using ASP.NET 2.0 then open this file:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config
Search for "path="*.asp"", then comment out that line. It'll like something like:
<!-- machine.config/ASP.NET 1.1-->
<add path="*.asp" verb="*"
type="System.Web.HttpForbiddenHandler"/>`
<!-- web.config/ASP.NET 2.0-->
<add path="*.asp" verb="*"
type="System.Web.HttpForbiddenHandler" validate="true"/>`
Locate the below file:
C:\WINDOWS\MICROSOFT.NET\FRAMEWORK\<FramworkVersion>\Config\web.config
where <FramworkVersion> is folder name:
open it in an XML editor .. (even notepad is fine)
and add below line :
<add path="*.asp" verb="*" type="System.Web.UI.PageHandlerFactory" validate="True"/>
under below XPath:
configuration/system.web/httpHandlers
replace the existing one!
Add below line:
<add extension=".asp" type="System.Web.Compilation.PageBuildProvider"/>
under below XPath:
/configuration/system.web/compilation/buildProviders
Worked like gem for me :)

Resources