I've created a small Class Library, with a HttpModule that uses a filter to add some html to every requested page served by IIS7.
I tested it first by registering the module in the web.config in a test web site, and it works as it should, but only in that one application.
I generated a dll, and created a strong named assembly.
I need to somehow add this assembly as a module in IIS on a server level, so that it works for all requests, on all applications, and for non-asp.net content as well.
So far, I have tried adding the .dll as a native module. This doesn't work. It's on the list of native modules, but it doesn't work.
I have installed the .dll in the GAC.
Reading on, it seems I have to add the assembly as a managed module, and then choose it in the dropdown list under "add managed module" in IIS.
For this, I tried using the commandline tool appcmd, writing: "add module /name: string /type: string /preCondition: string"
I've had no success doing this, since I can't figure out what to set as type and precondition.
As I have read, the modules registered in IIS should work for all applications in all sites, and all requests.
The point is to avoid having to register the module in every applications web.config file.
Any ideas?
After working with this for a bit, I managed to make it work.
Installing the assembly in the .net 4.0 GAC will not make it available in the type dropdown in IIS manager under "Add Managed Module".
What I had to do was:
Create the .net 4.0 Class Library, and compile it as a strong named assembly
Install it in the .net 4.0 GAC by using the gacutil, located in Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools
(Or make Visual Studio compile, sign and install the assembly automatically)
Add this line under <modules> in applicationHost.config: (it has to be done manually, it can't be done in the manager)
<add name="MyName" type="NameSpace.ClassName" preCondition="managedHandler,runtimeVersionv4.0" />
This makes the module run on requests to sites developed in .net 4.
It appears, however, that requests to sites developed in pre .net 4 versions can't use a module created in .net 4.0. So if you make requests for pages in a site created in .net 3.5, the module will not work.
Another observation:
After you have added the module to IIS via the applicationHost.config file, if you open the IIS manager, highlight the servername in connections and click modules. You will see the .net 4 module on the list.
Double click on it, and you'll then see the settings for it. You'll see that the "Invoke only for requests to ASP.NET applications or managed handlers" checkbox is checked. If you uncheck it, and hit ok, you'll get an error saying that the assembly hasn't been installed in the GAC.
But didn't I just install it succesfully in the .net 4 GAC? And didn't I just see the module run in a request?
If you go ahead and save the settings anyway, you get a runtime error, and if you look in applicationHost.config, you'll see that your previously manually added module settings has changed.
But what if I want to "Invoke only for requests to ASP.NET applications or managed handlers?
I am now able to run the module on every request. The reason it didn't work before was a totally un-related error on my part.
So, the steps involved to make it work is:
Write the code you want to run on every request, as a .net 3.5 Class Library.
Compile it as a strong-named assembly.
Install the assembly in the GAC.
In IIS7 manager, select the server name in connections, click Modules, click "Add managed module" in actions.
write a name for the module and choose your newly installed assembly in the type dropdown.
Make sure the site uses an application pool running in integrated mode.
Of course, it's not always a good idea to let all code run on all requests, so you may need to filter some of the requested files.
One question remains though!
There are now two GAC's, Microsoft.NET for .net 4.0, and Windows GAC for pre .net 4.0.
Because I created my assembly in .net 3.5, it was installed in Windows GAC, and therefore it was available in the type dropdown in IIS manager.
When I created my assembly in .net 4.0, it was installed in the Microsoft.NET GAC, and as a result, it was NOT available in the type dropdown in IIS manager.
The question is: How do you add a .net 4.0 assembly as a managed module in IIS7, and have it run like my 3.5 managed module?
This must be possible, right?
You have to add a module at a server level. You can do that from command line:
appcmd add module /name:string /type:string /preCondition:string
To get command line help execute: appcmd add module /?
In short, it must look like:
appcmd add module /name:AnyNameOfYourChoice /type:YourClassNameSpace.YourClassName
/preContition parameter is optional.
More details here.
OR
Do it from IIS Manager by going to server node -> Modules -> Add Managed Module
More details here. (bottom of the page)
Related
I am very new to web services. I have wrote a web service application. When I run it from visual studio, everything works fine and my local website comes up. But after I deployed it in IIS, I can't browse it from iis and i get the following error! I am confused about this error for a day! Can some one help me?
XML Parsing Error: no root element found
Location: http://localhost:99/WebService.asmx
Line Number 1, Column 1:
I faced a similar issue when I deployed a project on my local new computer. By default, ASP.NET is installed but disabled in Windows.I had to enable it before my project run. See Install IIS and ASP.NET Modules for details.
Make sure that all the required modules are enabled.
I had same issue, but had ASP.NET modules installed. Apparently had to change .NET Framework Version from v2.0 to v4.0 and site was showing as it should. You need to go to IIS, Application Pools, double click the one that has older version of .NET and set the relevant one. Maybe this will be helpful for someone else.
Our company ships an MVC based product (targeting v4.5) which has stopped working on a customer site for what appear to be environmental issues - a build which worked with no problems once upon a time now gives a 403.14 - The Web server is configured to not list the contents of this directory.
.
What I think is happening...
The user accesses http://server/AppName
Because it's an MVC app, the default route (Reports/Index) should be used.
Instead IIS is looking for a default document...
... and, not finding one, it assumes the user wants to list the contents of the directory...
...which is not enabled so it throws a 403.14.
.
What I've tried so far...
Accessing the route directly.. results in 404 error. So I'm pretty
sure IIS doesn't realise it should use routing.
Use aspnet_regiis to register ASP.Net with IIS. This was done from the Framework64 folder since...
OS is 64 bit - Windows Server 2008 (Standard without Hyper-V)
IIS is 64 bit - though Enable 32-Bit Applications is true
Checked AppPool is targeting v4 of the framework - it is.
Changed AppPool mode to Classic - was pretty sure it should be integrated but was worth ruling it out. It is now back to Integrated
Confirmed RunAllManagedModulesForAllRequests is set to true in the web.config.
Checked permission conditions defined in <system.webServer> section of web.config are met - they are.
Created the simplest of MVC applications and deployed it - same problem.
Running the command shell as Administrator unregistered ASP.Net using aspnet_regiis -ua and re-registered using aspnet_regiis -enable -i. We hit a couple of permission problems - and the Temporary ASP.NET Files directory was missing but once they were address we were back to the same error.
Added a simple default.htm - when present, this is served in response to the http://server/AppName request.
I'm clean out of ideas and all google hits suggest some combination of the above - or enabling directory browsing (which I think is just a symptom rather than the root cause).
Also, not sure if it's relevant but the amount of configurable elements available for the application in IIS seems a bit below what I would have expected...
Have you Checked the user the application pool process is running under? I think Your site needs to run with permissions to execute the .net libraries and I've seen this just change for seemingly no reason (probably related to an overzealous update to the system).
You can try with the Enabling directory browsing .
assuming you are under Windows Server 2012 or Windows Server 2012 R2
On the taskbar, click Server Manager.
In Server Manager, click the Manage menu, and then click Add Roles
and Features.
In the Add Roles and Features wizard, click Next. Select the
installation type and click Next. Select the destination server and
click Next.
On the Server Roles page, expand Web Server (IIS), expand Web
Server, expand Common HTTP Features, and then select Directory
Browsing. Click Next.
On the Select features page, click Next. On the Confirm installation
selections page, click Install. On the Results page, click Close.
if you using the Windows PC try this in your command prompt as follows:
go to C:\Program Files\IIS Express
then press Enter:appcmd set config
/section:system.webServer/directoryBrowse /enabled
Maybe this is your case https://forums.iis.net/t/1157304.aspx
SQL Server Reporting Services creates a folder called Reports by
default if you install it on IIS. If you install SQL 2008 then
Reporting Services doesn't need to use IIS and instead will try to
reserve the URL with the HTTP.Sys service.
I believe this is the cause of the conflict you are seeing. What you
could try is changing the URL that Reporting Services uses via the SQL
Server Configuration Wizard.
Also I found that
Report Manager of SQL Server can use reports path http://<server name>/reports
Configure a Native Mode Report Server for Local Administration (SSRS)
I think the problem is IIS features that are not installed yet. I have met this kind of problem frequently in Windows Pro. Make sure to turn on every feature under Internet Information Service -> World Wide Services because by default IIS is configured to use WebForms. So there might be some features that not installed yet to use MVC, especially ISAPI filters. In my case, that was the solution. I hope it helps.
Something similar i encountered using VS 2017 & ASP.NET MVC.
Was working on the project for long with no problems at all but suddenly the routing started misbehaving & stopped working.
So I changed the Port in Project Properties Page & it started working.
I really don't know what is the relation between a port & MVC routing modules. Someone else can enlighten if at all this helps.
I had the same problem and I just created an application pool out of the Default Web Site in IIS and stoped the default web site. With that difference you will not have the application pool's path
I know it's been a long time since this question but i've had the same problema recently. I've tried every single configuration, just like #amcdermott did, but the only action that solve the problem was reinstalling .NET Framework.
My app was built under .NET Framework 4.5.2. The application server had the version 4.6.1 and 4.5.2 installed. So, i uninstalled all framework versions and installed the one that i needed.
Please, make sure that no other applications use superior versions of .NET Framework if you going to try this solution.
Here are some quote I find on Microsoft official site which I think may help:
For site administrators
This problem occurs because the Web site does not have the Directory Browsing feature enabled, and the default document is not configured. To resolve this problem, use one of the following methods:
Method 1: Enable the Directory Browsing feature in IIS (Recommended)
To resolve this problem, follow these steps:
Start IIS Manager. To do this, click Start, click Run, type inetmgr.exe, and then click OK.
In IIS Manager, expand server name, expand Web sites, and then click the website that you want to modify.
In the Features view, double-click Directory Browsing.
In the Actions pane, click Enable.
Method 2: Add a default document
To resolve this problem, follow these steps:
Start IIS Manager. To do this, click Start, click Run, type inetmgr.exe, and then click OK.
In IIS Manager, expand server name, expand Web sites, and then click the website that you want to modify.
In the Features view, double-click Default Document.
In the Actions pane, click Enable.
In the File Name box, type the name of the default document, and then click OK.
Method 3: Enable the Directory Browsing feature in IIS Express
Note This method is for the web developers who experience the issue when they use IIS Express.
To do this, follow these steps:
Open a command prompt, and then go to the IIS Express folder on your computer. For example, go to the following folder in a command prompt:
C:\Program Files\IIS Express
Type the following command, and then press Enter:
appcmd set config /section:directoryBrowse /enabled:true
I want to include configuration for the Application Warmup module for IIS 7.5 in my application's web.config file ( an <httpWarmup> element inside <system.webServer>)
This works fine when the module is installed, but if I want to deploy the application to a server without the module installed (e.g. IIS Express) I get
HTTP Error 500.19 - Internal Server
Error
The requested page cannot be
accessed because the related
configuration data for the page is
invalid.
Can this be done? Is there a setting to make IIS ignore extra elements in <system.webServer> that it doesn't recognise?
Thanks
If you're using Visual Studio 2010 then you can use the web.config transformation feature. Using transformations you can, in combination with the website 'Publish' tool, transform your web.config and add/remove settings depending on whether you're doing a debug or release build.
For more information see:
Web.config Transformation Syntax for Web Application Project Deployment
How to: Transform Web.config When Deploying a Web Application Project
Scott Hanselman has a great demo of this feature:
Web Deployment Made Awesome: If You're Using XCopy, You're Doing It Wrong
This works with ASP.NET 2.0 and 4.0.
If you're still using Visual Studio 2008 then it's still possible to achieve this.
First off is to use a brute force approach and maintain multiple web.config files. When you build the project in VS you use a pre-built event swap in the correct web.config file. I've used this technique before but Scott Hanselman (as always) has a nice worked example:
Managing Multiple Configuration File Environments with Pre-Build Events
If you're using MSBuild directly then you could use a build task to modify the web.config files. There's an extension library available from the MSBuild Community Tasks Project which provides additional extensions to MSBuild to make these tasks easier. The XmlMassUpdate task is probably the task you'd want to use. I'll be honest and admit that I'm only scratching the surface of MSBuild at the moment and haven't actually tried this, but (and I don't mean this in a LMGTFY way) googling XmlMassUpdate returns a rich seam of useful looking hits.
i created an asp.net project in sharpdevelop. i wanted to get started to see how debugging is and i am stuck already. How do i run the ASP.NET project? It just says its configured as a DLL. How do i launch it as a webpage. I see "start browser in url" but how do i get my code in a webpage or what do i use to do it? Also can i debug while doing so like i would in MSVS?
SharpDevelop does not have great ASP.NET support. It does not have a visual web forms designer, for example. If you need that I suggest you look at using Microsoft's Visual Web Developer Express Edition.
To be able to run, view and debug your ASP.NET web project with SharpDevelop you can use the Cassini personal web server. There is a closed source version of Cassini from UltiDev which I have not used. There is also an open source version of Cassini for .NET 3.5 which I have used. The open source version does need you to compile it from source however.
Once you have Cassini compiled you can do one of the following to debug your ASP.NET web project in SharpDevelop:
1) In the project options (Debug tab) choose Start External Program and then browse to the Cassini executable.
In the Command line arguments field specify the command line arguments for Cassini, for example:
d:\Projects\MyAspNetProject 8080 /
(The first parameter should be the folder containing your web.config and Default.aspx web page. The second parameter is the port number that Cassini will listen on. The third parameter is the virtual root to use.)
Save these project options and then when you select Debug | Run or press F5 you should be able to run and debug your ASP.NET project.
2) Alternatively you can start Cassini manually, with the command line arguments as described above, and leave it running in the background.
Then in the project options select Start Browser in URL and enter the URL for Cassini, for example:
http://localhost:8080/
Since SharpDevelop 4.2 there is support asp.net mvc3.
For debugging you can use either iis or iisexpress
I'm comparing it Java where you can start your application server in debug mode, then attach your IDE to the server. And you can change your code "on the fly" without restarting the server. As long as your changes don't affect any method signatures or fields you can just hit recompile for a class and the application server (servlet container) will reload the class.
I suppose this is impossible in ASP.NET since all classes are packed into assemblies and you cannot unload/reload assemblies, can you ?
So when you have an .aspx page and an assembly deployed to GAC and your codebehind changes you have to redeploy the assembly and reset IIS. I'm talking about Sharepoint applications in particular and I'm not sure whether you have to do iisreset for private assemblies but I guess you have too.
So the best way to debug aspx pages with code behind I guess would be to get rid of the codebehind for the time of active debugging and move into the page, then when it is more or less working move it back to codebehind. (This would be applicable only for application pages in Sharepoint, site pages don't allow inline code )
How do you approach debugging of your ASP.NET applications to make it less time consuming?
From Matt Smiths blog on how to get F5 debugging with sharepoint. A very cool trick.
Create a web application project in Visual Studio (File -> New -> Project -> ASP.Net Web Application, not File -> New -> Web Site).
Move the .csproj and .csproj.user files, along with the Properties folder, into C:\inetpub\wwwroot\wss\virtualdirectories\, where is the name or number of the web application corresponding to the SharePoint site you'd like to debug on.
Attach the project to an existing solution (e.g. STSDEV project).
Set as startup project (right-click project name, "Set as Startup Project").
Access project properties (right-click project name, "Properties") and click
Under the "Servers" setting, click "Use IIS web server", then enter the URL to the SharePoint web application you want to debug on, e.g. http://mymachine:99.
Yes private assemblies DO NOT require reset of the IIS. So you should just to xcopy new version to the application's Bin directory and refresh the page (e.g. by VS post build event as I did).
But there are some trade offs. You should decrease trust level in application web.config file:
<system.web>
...
<trust level="WSS_Medium" originUrl="" />
...
</system.web>
By the way. I do not suggest to deploy like this. It's just workaround for comfort write-test-debug cycle length.
If you are using the GAC, you can at least do iisapp.vbs /a "App Pool Name" /r instead of iisreset (it's quicker to recycle a single app pool than to restart IIS).
First, develop on a computer running SharePoint. Preferably, this means running Windows Server 2003 on Virtual PC or VMWare. This will let you deploy and debug SharePoint code directly, rather than having to copy files between servers and use the remote debugger.
Use a VS add-in to simplify the process of deployment and debugging. I've been using WSPBuilder but I think there are others out there. WSPBuilder has commands to deploy solutions, package them as WSPs, and attach your debugger to the local IIS process. It won't allow you to add/remove assemblies on the fly, but you can set breakpoints and run code through the Immediate window in VS.
Depending on how your production server is configured, it's usually a good idea to develop on a server with full/trust security settings, including disallowing code blocks in ASPX files. This makes debugging a little more difficult, but it reduces the number of nasty surprises you'll have when your code is finally deployed to production.
And you can change your code "on the fly" without restarting the server
You can accomplish this with ASP.net if you make a Web Site project (as opposed to a Web Application Project). Using a Web Site project, you can post changes to code-behinds without having to refresh anything on the server, and the server does the compile work for you on all code changes. See here for more info on this.
This should also solve your difficulties with deploying the assembly to the GAC. As the server handles all compilations for Web Site projects, you wont have to redeploy any assemblies when changing files.
Use an automated testing framework (NUnit) to write integration tests. This won't work for everything, but of course, it depends on what you're testing.
If you also have TestDriven.NET installed, you can run individual tests with the debugger. This has been helpful.
WSPBuilder Extensions has a "deploy to GAC" shortcut, unfortunately it never works for me. But it's a really quick way to code->compile->test.
If you're not using WSPBuilder Extensions, you can instead open a command prompt and run
gacutil /u yourassemblynamegoeshere
gacutil /i yourdllgoeshere.dll
If you do this often, you can put it in a post-build event or in a batch file. Also, I'm unclear whether the gacutil /u (to remove the DLL first) is necessary.
What it seems like you're trying to do is tell Sharepoint "When I start debugging in Visual Studio, use the version of the DLL that was compiled in the project's /bin/debug directory instead of the version of the DLL that is registered in the GAC." I haven't solved that problem, but here is how I debug Sharepoint.
A developer machine is Win2008, IIS 7, MOSS 2007, VisStudio 2008, and WSP Builder installed. Inside VS2008, a button is added to attach to w3p.exe process, Andrew's HOWTO attach to w3p
The solution file has two projects:
* First project is the .WSP that deploys all the app pages, including the DLL. Use WSPBuilder menu items for handling the .WSP creation and deployment.
* Second project is for the DLL behind the pages.
If you want the DLL to be copied to the GAC regularly, add a post-build event to the DLL's project that copies from /bin/Debug to the GAC. But, these days, I find I have just been recompiling the solution and then deploying the .WSP using the menu items, and then starting up the debugger using the button. It takes me an F-key and 3 clicks and about a minute for most of my projects, but I suppose it could be quicker.