Category Archives: ASP.NET

The Web project blablabla requires missing web components to run with Visual Studio. ASP.NET Web pages with Razor syntax

missing web pages with razor syntax

Ever encountered this strange popup in VS2010 after several hours of happily working with MVC? And now VS thinks, that something is wrong with your Razor components?

Well the thing might be, that you just updated from SVN and your web.config file was modified in a bad way, say like this :

  <connectionStrings>
<<<<<<< .mine
    <add name="blablaConnectionStringFullSQL" connectionString="some-connection-string" providerName="System.Data.SqlClient" />
    <add name="blablaConnectionStringFullSQLalt" connectionString="some-connection-string" providerName="System.Data.SqlClient" />
=======
    <add name="blablaConnectionStringFullSQLalt" connectionString="some-connection-string" providerName="System.Data.SqlClient" />
    <add name="blablaConnectionStringFullSQL" connectionString="some-connection-string" providerName="System.Data.SqlClient" />
>>>>>>> .r199
  </connectionStrings>

Well at least, this was my case, so as a first shot, take a look at files that conflicted after update.

Hope this helped a bit.

ASP.NET WebResource behavior in Web User Control (.ascx file)

Today very talented colleauge of mine sent out to us very nice catch about requesting resources from .ascx file.

So this is the mail (yes, he said OK to publish it :))

Hi All,

pay attention when requesting resources using embedded resource and WebResource.axd.

Generally you use this:

Page.ClientScript.GetWebResourceUrl(GetType(), "MyNamespace.Folder.resourceName.ext")

But in case you do this in ASCX code behind it won’t work (at least for me :))

To make it working you must pass explicit type to the method:

Page.ClientScript.GetWebResourceUrl(typeof(MyType), "MyNamespace.Folder.resourceName.ext")

Or course do not forget to register handler in .config:

<add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="true" />

and resources in .cs file:

[assembly: System.Web.UI.WebResource("MyNamespace.Folder.resourceName.ext ", "image/png")]

I just wanted to share this with you. Btw you can reach author of this here :

http://www.linkedin.com/profile/view?id=122801475&locale=en_US&trk=tyah

Thx for sharing Matej.

Trace.Write not working in my ASP.NET handler – How to trace your generic .ashx handler

Today I needed to trace my small ASP.NET application which consists of one .ashx file that will handle requests. Because this handler will respond with text I need to write my trace somewhere else than to the bottom of the page (which is possible in .aspx page). I also can’t write Trace=”true” in .ashx file. So how to make your trace work?

  • Open web.config file and add
    <trace enabled="true" />

    in

    <system.web>

    node,

  • Also add
    <system.diagnostics>
     <trace autoflush="true" indentsize="4">
     <listeners>
     <add name="webListeners"
     type="System.Web.WebPageTraceListener, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
     </listeners>
     </trace>
     </system.diagnostics>

    in <configuration> node. (I found out that although I call Trace.Write in my code, nothing is written anywhere),

  • Call Trace.Write or some other method in you code.

When you execute request against you handler (Trace.Write gets executed) and then go to yourapp/trace.axd you will be able to see all requests and clicking on you your_handler_name.ashx’s file View Details link you will be able to see something like this :

trace from asp dot net handler

Without adding webListener entry to web.config you wouldn’t be able to see any of your Trace.Write messages. In normal .aspx file this works out of box. You just enable it in web.config file and use Trace.Write and that’s all. Pages derives from System.Web.UI.Page but handlers from IHttpHandler, so this is the difference.

Here is whole sample app packaged, if you need it (look for TraceHandlerWebApplication.zip file) :

https://skydrive.live.com/redir.aspx?cid=78a5783de37d2ebe&resid=78A5783DE37D2EBE!1782&parid=root

Enjoy.

Don’t forget to add Telerik’s WebResource handler to both sections in web.config file

Today I came across easy to spot but nasty little problem when deploying ASP.NET app with Telerik ASP.NET AJAX controls.

When creating the project, some coleague of mine (propably) used old web.config file to create new app (because of some common classes and setting that we use). Anyway, with Cassini everything worked fine, but when deployed on IIS 7.5, I got an

‘~/Telerik.Web.UI.WebResource.axd’ is missing in web.config. RadScriptManager requires a HttpHandler registration in web.config. Please, use the control Smart Tag to add the handler automatically, or see the help for more information: Controls > RadScriptManager

error. I googled out in some discussions that : you should set the Managed pipeline mode from Integrated to Classic. This indeed solved the problem with behaving IIS 7.5 as old 6.0 (with handler registered in old web.config node), but I wasn’t convinced that to use Telerik’s controls, I should use old type of pipeline. That would be really strange. So I was searching around, what is the real problem.

I looked in web.config file and then it finally hit me. :)

Our old web.config file registered Telerik’s handler only in old <system.web> section for IIS 6 (and that sufficed for cassini and IIS 6.0) and not in new <system.webServer> section. So I had to add this piece of xml to web.config :

<handlers>
    <add name=”Telerik.Web.UI.WebResource”  path=”Telerik.Web.UI.WebResource.axd” verb=”*” type=”Telerik.Web.UI.WebResource, Telerik.Web.UI” />
</handlers>

(Please note, this snippet is dated 2011 – it worked at that time, I suppose in 2014 this will be generated in a different way)
This would be of course be added by RadScriptManager’s menu hidden in it’s smart tag in design mode, but we didn’t used this approach as everything worked on our dev machines.

So, when deploying to IIS 7.0 and up, don’t forget to register handlers to both nodes or use Telerik’s RadScriptManager menu option. :)

If you want to learn more :

http://www.telerik.com/help/aspnet-ajax/troubleshooting.html

http://msdn.microsoft.com/en-us/library/46c5ddfy.aspx

http://stackoverflow.com/questions/716049/what-is-the-difference-between-classic-and-integrated-in-iis7