How to access system.webserver web.config node in .NET 2 - c#-2.0

Are there any .NET APis that can read/update the system.webServer node in web.config? I know I can do it via reading/parsing the web.config file as xml but that's awkward.
To read/update the system.web node in .NET 2 I can use:
HttpModulesSection httpModulesSection = (HttpModulesSection)configuration.GetSection("system.web/httpModules");
But is there any API based way of accessing system.web/modules using .NET 2?
I have to reference the .NET 2 version of system.web.configuration because I don't know in advance if my web app will be run on a server with .NET 2 or 3.5. So it is limited to .NET 2 API calls only.
Thanks

You need to use the Microsoft.Web.Administration.dll assembly. You can check this blog post.

Related

Is it possible to deploy WCF and MVC applications to 1 application?

I have WCF application and MVC application in 1 solution. When I deploy projects with WCF, I always deployed them like 2 sites. Firstly, I deployed WCF application to IIS, then MVC application and use WCF's endpoint address.
My question is that, is it possible to deploy MVC and WCF applications together, not like 2 separate site? WCF runs inside ASP application. And in IIS we have 1 site.
Yes it is possible. Merge WCF application & MVC application together into a single project. If your WCF project contains too many classes you can move them into a class library.
But you must move following items into web application project:
Move .svc file into MVC project, this file does all the magic to
host your WCF service into IIS.
Move System.Service Model section of WCF application into MVC
project.
I done this.. Works well in local...
But When you host it in an IIS or web deploying
add this code in webconfig
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

ASP.NET Web Api metadata exchange?

Does anyone knows if there is any way to expose the new ASP.NET WEB Api REST interface metadata as with WCF (/help)?
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true"
automaticFormatSelectionEnabled="true" />
</webHttpEndpoint>
</standardEndpoints>
Help page generation is not supported in the first drop of ASP.NET Web API (in ASP.NET MVC 4 Beta) but is planned to be supported in later versions. The generation of the Test Client website is also planned to be supported.

Custom authentication : Odata services

Do you know of a way for me to create a customer authentication in Odata services? I don't want to use the default ASP.NET membership model and NetworkCredential.
I have already referred section : authentication-part-6-custom-basic-authentication.aspx. But i am not able to debug Httpmodule i.e Init() of Httpmodule
This depends on what version of IIS you are deploying/testing in.
I found that when using IIS version less than 7, your new HttpModule should be declared in System.web/HttpModules tag. In version 7 and higher, it should be in the System.webserver/Modules tag.
Within IIS, enable just anonymous authentication.

ASP.NET MVC - Is it even possible to have multiple MVC projects on the same server?

I'm having so many problems getting more than 1 MVC project up and running on the same server... I'm using a Windows XP system running the default IIS (5.1 I believe).
At this moment I'm even building WebSetup projects for every project I create to make sure everything goes well, while these projects could very easily be deployed using XCopy.
Bottom line, I can get a MVC project (e.g. ContactManager example) running at: http://servername, OR http://servername/ContactManager. But as soon as I have a project at both locations the horror starts
"title is not a member of ViewPage" -> yeah, right...
Section or group name 'system.web.extensions' is already defined. -> sure
let me <clear /> or <remove /> that one, oh that's not valid...
Is it even possible to have more than 1 ASP.NET MVC project (application) running on the same Windows XP machine?
http://server/ Root project (MVC)
http://server/app1 Application 1 (MVC)
http://server/app2 Application 2 (MVC)
http://server/appX Application X (MVC)
Can somebody name some points of attention or something?
Is it even possible to have more than 1 ASP.NET MVC project
(application), running on the same
Windows XP machine?
Yes, it is absolutely possible to have more than 1 ASP.NET MVC application at same Windows XP machine. I've just created two new ASP.NET MVC applications on my test machine running fresh Windows XP SP3 and they works smoothly.
UPDATED:
I've just created 3d application:
IIS root path changed to that application
Added mapping .* to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll.
Checked anonymous access
Still all 3 applications works very well
UPDATED:
There is one issue with mapping .* to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll at the server root: all your not-MVC plain ASP.NET applications will stop working.
Home this helps
Yes this is possible. I have 3 MVC applications running under 1 main MVC application.
- Main site
- Administration
- Sub App 2
- ...
However, you need to check the following details.
check the main and sub applications are all setup to use the wildcard mapping for MVC with aspnet_isapi.dll.
due to inheritance of web.configs you need to set a property in your root MVC application... wrap this around your < system.web >
<location path="." inheritInChildApplications="false">
<system.web>...
</location>
IIS5.1 that comes with XP only supports one web site (but multiple virtual directories). This i believe will be your limiting factor.
IIS6.x and above where you have many web sites (and many application pools) is preferred when trying to get multiple MVC apps on the same server.
EDIT You could always use the free version of VMware Server and just create heaps of VMs with XP for testing/development.
are there 2 separate application defined in IIS?
On XP, a solution would be to use an Apache server with Mono 2.4. It works very well with ASP.NET MVC, and even with SQL Server (<= 2005). Hopefully, one day, we'll see this packaged with some future version of Xamp or EasyPHP :) That will enable everybody who is curious to give it a try.
Ensure that the root folder of each application, in IIS manager, is set to be a different web application.
I came across this post that should give you an easy and clean way to do it (with subdomains):
http://blogs.securancy.com/post/ASPNET-MVC-Subdomain-Routing.aspx

How to make ASP.NET MVC work in IIS 6?

I have installed .NET Framework 3.5 SP1 and ASP.NET MVC CTP in a Windows Server 2003 R2 box, but my ASP.NET MVC site still doesn't work on that server. I was searching the internet and IIS for a solution and I noted that I can't choose other .NET Framework version besides 2.0 for my virtual directories. I'm almost sure if I correct this I can make my site work there.
Currently the main "/" URL answers with:
Directory Listing Denied
This Virtual Directory does not allow contents to be listed.
And the "/Default.aspx" URL answers with:
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Section or group name 'system.web.extensions' is already defined.
Phil Haack has a pretty good writeup here
http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx
I had the similar issue.
I recently upgraded my server to support .net framework 4.0.
Converted my application to support .net fx 4.0.
Deployed the application on sever and trying to test .. I get "HTTP Error 404 - File or directory not found"
Solution
Open IIS Manager, expand the master server node (i.e, the Servername node), and then select the Web service extensions node.
In the right pane of IIS Manager, right-click the extension "ASP.NET v4.0.*".
Click the Allow button.
Besides Jason's answer, the common things to look for is:
Enable Wildcard mapping and point it to the aspnet assembly Phil mentions in Jason's link.
The /default.aspx error you are getting seems to be a web.config configuration error. At the very top of your web.config, look for:
<sectionGroup name="system.web.extensions"
Most likely it is defined twice. You only need the reference for the RC build you have. If you need the exact RC references, create a new ASP.NET MVC Web Project in a temp folder. And then grab the web.config from it.
-E
I also encountered this problem, in my case the solution was to uninstall the ASP.NET MVC Beta.
The application I was trying to get working had the version 1 MVC dlls bin deployed and once the Beta was uninstalled it all worked fine.
Similar issue: We tried to install an MVC4/.NET 4 app on an IIS6 box, set up everything as described, and got same error:
Directory Listing Denied
This Virtual Directory does not allow contents to be listed.
For us, the final fix was to add the UrlRoutingModule to the web.config:
<add name="UrlRoutingModule"
type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
Which makes sense, but I don't know why we needed to explicitly add it and others didn't. (We are running in a directory under Sharepoint, maybe related...)

Resources