VS2010 development web server does not use integrated-mode HTTP handlers/modules - visual-studio

I am developing an ASP.NET MVC 2 web site, targeted for .NET Framework 4.0, using Visual Studio 2010.
My web.config contains the following code:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="XhtmlModule" type="DomenicDenicola.Website.XhtmlModule" />
</modules>
<handlers>
<add name="DotLess" type="dotless.Core.LessCssHttpHandler,dotless.Core" path="*.less" verb="*" />
</handlers>
</system.webServer>
When I use Build > Publish to put the web site on my local IIS7 instance, it works great.
However, when I use Debug > Start Debugging, neither the HTTP handler nor module are executed on any requests.
Strangely enough, when I put the handler and module <add /> tags back into <system.web /> under <httpHandlers /> and <httpModules />, they work. This seems to imply that the development web server is running in classic mode.
How do I fix this?

You don't. WebDev.WebServer.exe does not and cannot support integrated pipeline.
So, if you have code that cannot be written to perform in both environments you will need to use a local IIS for development.
Basically, system.web is the place to configure webdev server and IIS5-6 handlers and modules. system.webServer is for IIS7 handlers and modules, as you know.
Reference:
Each request in WebDev.WebHost40 (and previous versions) is processed by HttpRuntime.ProcessRequest
(which does not support integrated pipeline mode). This is the method used in all three versions of WebHost.WebServer.dll (the core of WebDev.WebServer.exe)
And the word of some dude who is fairly familiar with the inner workings of Cassini/WebDev by virtue of managing this project. ;-)

I'm not sure if I'm too late in answering, but while it's known fact that the Cassini server doesn't support integrated pipeline mode, you can still test locally using the classic pipeline by adding it to the httpModules section of system.web in your web.config:
<system.web>
<compilation debug="true" targetFramework="4.0"/>
.
.
.
<!-- HTTP Modules using Classic Pipeline -->
<httpModules>
<add name="YourHttpModule" type="ACME.YourHttpModule"/>
</httpModules>
</system.web>
<system.webServer>
<!-- HTTP Modules using Integrated Pipeline -->
<modules runAllManagedModulesForAllRequests="true">
<add name="YourHttpModule" type="ACME.YourHttpModule"/>
</modules>
</system.webServer>
You'd probably want to remove the httpModules section from your production web.config.

Got this today while running in visual studio 2012. Found the reason was visual studio launched the old web server that comes with 2010 and as explained above it can't work there. Changed to IIS Express by right click on properties, choose "Web" tab and and selecting IIS Express option. Then launching debug mode will start in IIS Express and this aparently supports operations such as Request.Headers.Add or whatever caused your exception.

Related

B2C Authentication with WebForms

I have a legacy WebForms application. I need to add Azure B2C authentication to it. My application is using currently Microsoft.Aspnet.Identity. It does not have any startup.cs page. How can I make this migration?
Some minor things allow you to switch your site to use AAD or aadb2c for authentication.
Get the necessary OWIN NuGet packages, Add some startup code to use the OWIN authentication libraries ,Register your application in AADb2c.
Update your web.config with appropriate OAuth values.
Even though OWIN didn’t exist when you wrote your Web Forms app, you can still use it and it will significantly simplify the process.
In the Visual Studio menu, select Tools > NuGet Package Manager > Package Manager Console.
Make sure your web project is selected in the Default project drop down.
Run the below commands:
install-package Microsoft.Owin.Host.SystemWeb
install-package Microsoft.Owin.Security.OpenIdConnect
install-package Microsoft.Owin.Security.Cookies
You may check the references and then follow this B2C-WebForms-DotNet
References:
c# - ASP.NET Web Api - Startup.cs doesn't exist - Stack
Overflow
c# - OWIN Startup Class Missing - Stack Overflow
edit:
My web forms if for visual C# and could find owin start up :
Right click on App_Start > add item > under web , you can find it.
Please check if your project is visual c# .
edit 2:
Please check if below points help :
Maybe you can create new start up class by using owin library in the clas
Imports Microsoft.Owin.Extensions
Imports Microsoft.Owin.Security
Imports Microsoft.Owin.Security.Cookies
Imports Microsoft.Owin.Security.OpenIdConnect
Imports Owin
Imports System
Imports System.Configuration
Check the web.config file and remove this key setting and try
<add key="owin:AutomaticAppStartup" value="false" />
and also try add <add key="owin:AutomaticAppStartup" value="true " /> in web.config file
The following attribute will set the startup class to the StartUp class in the StartupDemo namespace.
[assembly: OwinStartup(typeof(StartupDemo.StartUp))]
Add appSetting element in the Configuration file
<appSettings>
<add key="owin:appStartup" value="StartupDemo.StartUp" />
</appSettings>
Check how owin detects start up owin-startup-class-detection -Microsoft docs
Other references:
owin-startup-class-not-detected
owin-with-vb-net-legacy-code-asp-net-web-forms
where-to-implement-startup-code-in-vb-net

CORS support in WebAPI, MVC and IIS with Thinktecture.IdentityModel

I am trying to implement CORS using Thinktecture.IdentityModel as mentioned in the link below:
http://brockallen.com/2012/06/28/cors-support-in-webapi-mvc-and-iis-with-thinktecture-identitymodel/
I tried Web API method and it didn’t work. So I went towards IIS route.
<system.webServer>
<modules runAllManagedModulesForAllRequests=“true“>
<add name=“MvcCorsHttpModule“
type=“Thinktecture.IdentityModel.Http.Cors.Mvc.MvcCorsHttpModule“/>
</modules>
</system.webServer>
And then again in global.asax you would configure the settings:
protected void Application_Start()
{
…
RegisterCors(MvcCorsConfiguration.Configuration);
}
private void RegisterCors(MvcCorsConfiguration corsConfig)
{
corsConfig
.ForResources(“Products.GetProducts”)
.ForOrigins(“http://foo.com”)
.AllowAll();
}
Now, it works in my local host (Windows 8, VS 2012) but when I push it to prod (IIS 6), it doesn’t work. Is there other settings to make it work in IIS 6? Why would it work in the localhost but not when I push it to production.
Your issue is the inverse of this.
Modules are registered differently in IIS6 to IIS7+.
<configuration>
<system.web>
<httpModules>
<add name="MvcCorsHttpModule" type="Thinktecture.IdentityModel.Http.Cors.Mvc.MvcCorsHttpModule"/>
</httpModules>
</system.web>
</configuration>

What is in a mysql provider?

I have been toiling with an issue with mysql connector on and off for the past 3 months using a workaround. I even filed a bug report recently. However, I have found multiple instances of mysql connector failing in situations of advanced linq use. Some dating back to 2009 ( 3 years ) and still unresolved. In almost every instance, the user switched connectors.
I am considering doing the same. However, I came across looking at where mysql connector exists inside of my project. From what I can tell, it is only an included .dll (mysql.data and mysql.data.entity). After that, it is referenced only in web.config.
The first reference to the connector is in the connection string, providerName = "MySql.Data.MySqlClient".
The second reference is the definition of the provider
<system.data>
<DbProviderFactories>
<clear />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient"
description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, mysql.data, Version=6.5.4.0,
Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
The third is inside of the assemblies
<add assembly="mysql.data, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
And the last is another assembly reference
<dependentAssembly>
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.5.4.0" newVersion="6.5.4.0" />
</dependentAssembly>
Is this really the whole footprint of the connector?
Is this really the whole footprint of the connector?
Yes and no.
Yes
As far as the project which references the connector is concerned, this is the whole footprint. The only configuration that needs to be made is to have MySql.Data and MySql.Data.Entity added as references to the project. Usually these are inside of the packages folder, and are then copied into the bin folder once a reference has been added.
No
The connector has a lot of internal code going on. Because of where it is defined, the connector inherits from and extends on the DbProviderFactory. This extension involves many classes and sub classes which determine how the interaction to mysql is enacted. Because it is open source, the actual code can be downloaded from oracle.

Why do I get "Type could not be found" WCF error on IIS server but not locally with Visual Studio 2010? [duplicate]

This question already has answers here:
The type 'RestService.weddingservice', provided as the Service attribute value in the ServiceHost directive could not be found
(6 answers)
Closed 7 years ago.
The error is:
The type 'WF.XXX.WebServices.XXXXService', provided as the Service
attribute value in the ServiceHost directive, or provided in the
configuration element
system.serviceModel/serviceHostingEnvironment/serviceActivations could
not be found.
Stack Trace:
[InvalidOperationException: The type 'WF.XXX.WebServices.XXXXService',
provided as the Service attribute value in the ServiceHost directive,
or provided in the configuration element
system.serviceModel/serviceHostingEnvironment/serviceActivations could
not be found.]
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String
constructorString, Uri[] baseAddresses) +52742
System.ServiceModel.HostingManager.CreateService(String
normalizedVirtualPath) +1459
System.ServiceModel.HostingManager.ActivateService(String
normalizedVirtualPath) +44
System.ServiceModel.HostingManager.EnsureServiceAvailable(String
normalizedVirtualPath) +623
[ServiceActivationException: The service
'/XXXXX/XXXXXService/XXXXService.svc' cannot be activated due to an
exception during compilation. The exception message is: The type
'WF.XXX.WebServices.XXXXService', provided as the Service attribute
value in the ServiceHost directive, or provided in the configuration
element
system.serviceModel/serviceHostingEnvironment/serviceActivations could
not be found..] System.Runtime.AsyncResult.End(IAsyncResult result)
+687598 System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult
result) +190
System.ServiceModel.Activation.ServiceHttpModule.EndProcessRequest(IAsyncResult
ar) +304662
System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult
ar) +94
How to fix this error on the server?
Update on 9/18/2012:
I have Visual Studio 2012 and .NET Framework 4.5 installed on my machine but server has only .NET Framework 4.0. I am not sure if this matters, because I built the service with .NET Framework 4.0.
But strangely, I noticed a 4.5 feature when I run my project. It shows a URL to singleWSDL file, which is not available in .NET 4.0 version. Why does this show up when the project is built with .NET Framework 4.0? Here is the screenshot:
Update 9/19/12:
Here is the relavant web.config file:
<system.serviceModel>
<services>
<service name="XXXXService">
<!-- Use a bindingNamespace to eliminate tempuri.org -->
<endpoint address="" name="XXXXService"
binding ="basicHttpBinding"
bindingNamespace="#services.url#/XXXXService"
contract="WF.XXX.WebServices.XXXXService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="None" mapClientCertificateToWindowsAccount="true" />
</clientCertificate>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
To answer your questions
(1) Make sure you have built your project and the the dll which contains the service type XXXXService is placed in the bin directory.
(2) Single Wsdl is a new 4.5 feature. Since 4.5 is an in-place upgrade of 4.0 you will get the benefit of ?SingleWsdl even if you target your project to 4.0. But when you deploy the same service on a machine with just 4.0 then you will not be able to get this. To get this on your service machine make sure you have 4.5 on that too.
Hope this helps.
Thanks!
I had the same problem and the cause was that I had changed the namespace in the code files IService1.cs and Service1.svc.cs but forgot to change the namespace in the Service1.svc file.
E.G. in service1.svc
< % # ServiceHost Service="WcfService2.Service1" % >
must be changed to:
< % # Service="NewNamespaceName.Service1" % >
You can build the solution without Visual Studio catching the typo error.
I had the same issue. In my case, simply deleting the bin and obj folders and rebuilding fixed the issue.

Configure Active Directory in MVC3 project

I have a problem deploying a MVC3 project IIS server, the project runs well in my local machine, but not in the server the errors say's this
Parser Error Message: The supplied credential is invalid.
This is the line of configuration of my merbership Provider
<add name="MembershipADProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" applicationName="AtentoCNEHoraExtra" connectionStringName="ADConnectionString" attributeMapUsername="sAMAccountName" />
What could be wrong???
I found the solution to my problem, I have to modify the identity of the process model associated with the pool .NET 4 in the configuration on my IIS
The value that has by default was ApplicationPoolIdentity and I have to changed to NetworkService
This configuration can be made in ISS --> Application Pool ----> .Net 4---> Advanced Settings --> Process Model
I hope that helps to others

Resources