Serving ASP.NET in Windows 7 IIS 7 - asp.net

I have worked with IIS 5.1 (XP) and 6 (Server 2003) but I am a little lost on IIS 7 (Windows 7).
I install IIS from windows component, created a new website testweb, added virtual directory, pointed it to where to serve pages from. Converted that to application. Now when I visis the site, it does go to the location and it lists all the files (I have enabled directory listing) but when I when I go to the test.htm file (I added) in the folder, I get this
HTTP Error 404.0 - Not Found The resource you are looking for has been
removed, had its name changed, or is temporarily unavailable.
The file is obviously there as it was listed in the directory. If I click on .aspx file I get this
HTTP Error 500.21 - Internal Server Error Handler "ASPX handler" has a
bad module "ManagedPipelineHandler" in its module list
One problem that I had was I could not save test.htm file directly in the directory (c:\program files\product\web) from Visual Studio, I had to save the file in documents folder and then copy it over as administrator.
My questions are:
Do I need to specify default handlers in II7 for ASPX pages? I heard they are not there by default. This would be in Hanlders section. I have already added one by the way.
Do I have to add MIME type for ASPX pages as well. They are not there be default. If I had one, I run into different errors.
Can anyone clarify on the two questions. Thanks

For #1, did you install the static file portion of IIS?
For #2, try re-registering ASP.Net 4.0 by running something like:
%windir%\Microsoft.NET\Framework\v4.0.21006\aspnet_regiis.exe -i
(Depending your CPU you might want to use Framework64)
Also check that your app pool is targeting the 4.0 Framework and not the 2.0 Framework.

Related

Start an ASP.net website from a specific folder using IIS Express via command line

I've written and ASP.net MVC web application that needs to be installed as a "normal" application (or as close to it as possible). By which I mean, I need to have a "double click on exe file and the webappp opens in default browser" behavior, or as close to that as possible.
Being used to Java, I stupidly thought that I could use and embedded webserver to run it, but after a bit of research (correct me if I'm wrong here) it seems this cannot be done (only ASP.net Core can do that, but I'm using the traditional .NET Framework) and the web app needs to be run in either IIS or IIS Express.
So, after more research, this page:
https://learn.microsoft.com/en-us/iis/extensions/using-iis-express/running-iis-express-from-the-command-line
seems to suggest that launching a site from a specific folder via IIS Express is possible, by using a command like:
iisexpress.exe /path:"C:\Program Files\MyWebsite\bin"
where the path above contains my compiled ASP.net MVC website.
This, however, doesn't seem to work. When I issue that command I get the following output:
c:\Program Files\IIS Express>iisexpress.exe /path:"C:\Program Files\MyWebsite\bin"
Copied template config file 'c:\Program Files\IIS Express\AppServer\applicationhost.config' to 'C:\Users\MyUser\AppData\Local\Temp\iisexpress\applicationhost20179188941639.config'
Updated configuration file 'C:\Users\MyUser\AppData\Local\Temp\iisexpress\applicationhost20179188941639.config' with given cmd line info.
Starting IIS Express ...
Successfully registered URL "http://localhost:8080/" for site "Development Web Site" application "/"
Registration completed
IIS Express is running.
Enter 'Q' to stop IIS Express
So basically IIS Express starts, but it's not running my website from the folder I specified, it runs some (presumebly) default empty website, called "Development Web Site". I checked some urls, and I can confirm that is not my website, but just an empty shell with no pages or anything else.
What am I missing here? How do you start a website in IIS Express via command line? Do I have to "register" the website first somehow?
EDIT:
After a bit more research, I found out I can register a website explicitly by doing:
appcmd.exe add site /name:MySite /physicalPath:"C:\Program Files\MyWebsite\bin" /bindings:http://localhost:8081
and then start it with:
iisexpress.exe /site:MySite
This however doesn't solve the problem: when I browse to the website via browser all I get are 404 errors, there's no content at all.
One thing I also must point out: since an ASP.net website is compiled into a DLL file, I don't understand how simpy registering/starting it using a path to a FOLDER would work... how would IIS Express understand which DLL to load the site from? Seems like there are some crucial pieces missing here...
After further tinkering, I figured it out. I was pointing to the /bin directory of the website. Instead, you have to point to the parent directory, the one that contains the Web.config file.
So, in my case, I changed:
iisexpress.exe /path:"C:\Program Files\MyWebsite\bin"
to:
iisexpress.exe /path:"C:\Program Files\MyWebsite"
and now it works correctly

Asp.Net is looking for the web.config in the wrong place

I've got a strange issue - Up until now I've only worked on this application on a single machine. I've downloaded an asp.net web app onto a dev machine in a clients office.
When I try to run the application in debug mode through Visual Studio I get 500.19 error - typically this means a permission problem. I went through the motions of checking the permissions before I noticed the directory it was looking for the config file in.
The 'Config File' shown on the error is
\\?\C:\Users\{my-name}\Documents\{project-name}\web.config
however the correct location is actually
C:\Users\admin\Documents\projects\{project-name}\web.config
Does anyone know where the location of the web config is specified? I had always assumed it could only ever be in the root directory.
As it turns out the cause of this was upgrading to Visual Studio 2015.
Rather than a .suo file the new Visual Studio has a .vs folder with files specific to an instance of a project. The root directory of the development site is included in here.
I deleted the files and added .vs/* to my .gitignore file and had no more problems.
At our infrastructure it turned out that inside the web.config withing the node <system.webServer>, we had a nested node named <rewrite />. That one wasn't recognised by IIS.
By either removing that node or installing the missing feature (url-rewrite), the application started as expected.
In my case, the top level website in IIS had a physical path of:
C:\Users\MyUserName\Documents\My Web Sites
For some reason, this meant IIS refused to look anywhere else, even though my projects underneath had been converted to applications.
Fix for me:
Go to IIS
Right click on the top level website (i.e. 'Default Web Site', or the problematic website at the same level)
Select 'Manage Website > Advanced Settings'
Change the physical path to C:\inetpub\wwwroot
Save and reload website
I could then have any path for my applications and IIS could work it out as expected.
Assuming you mean Documents\projects\{project-name}\web.config instead of Documents\projects{project-name}\web.config you're seeing the effect of Application Scopes.
In IIS, multiple entirely separate web-applications can be part of the same website by being split-up into "Application Scopes" - which usually works by specifying a prefix path followed by the Scope root (prior to IIS7 an Application Scope could be a physical or virtual directory, since IIS7 they're always virtual directories, but can still represent a physical directory).
Open IIS Manager and select the (virtual )directory that Visual Studio created for your project and right-click it in the left-side Navigation pane and choose "Convert to Application", then ASP.NET will look for the web.config file (and the bin directory, amongst others) in this folder only, rather than the website root.
Note that the website root is also considered an application scope root, hence the common error message "Exception in "/" application". If you get a YSoD in another application root you'll see "Exception in "/subFolder" application" messages.

IIS 7 Wont Open My Aspx Files

I am new to IIS and it is annoying the hell out of me!
I have an asp.NET website that runs beautifully on visual studio 2010, so what i do, is publish the website, put the published website folder in the inetpub/wwwroot folder, connect all the dots, then in my browser i type in http://localhost:8080/A3Media/ and it brings up my index.html page. So the IIS is working correctly because it happily displays .html files. but when i try and access a .aspx file in my website. I get i weird 404 error saying the document doesnt exist. When it obviously does exist because... I checked... multiple times!
So i deducted that my IIS doesnt like .aspx files or anything to do with asp.NET.
So i make sure that i have all the asp.net modules installed by following the usual "windows features" and making sure the asp.net folder is ticked and installed, along with all the depending asp.net folders.
and my website still doesnt work.
have i missed something?
i have no idea:(
One of two options spring to mind.
Have you registered ASP.NET? aspnet_regiis.exe -i Link
cmd -> cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
C:\Windows\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis.exe -i
In IIS manager - Request Filtering - Is .aspx denied?
Make sure you convert your "A3Media" directory into ASP.NET Application via IIS Manager, please see Deploying ASP.NET Websites on IIS 7.0 for more details.

The requested page cannot be accessed because the related configuration data for the page is invalid

I am getting this error when I try to run an ASP.NET application without a web.config file.
The requested page cannot be accessed because the related configuration data for the page is invalid
as I read, we can run .NET applications without web config files, but when I tried it is giving me the error. I am using iis 7 on windows 7 machine.
When I create the application virtual directory inside inetpub/wwwroot it works fine. Why doesn't the other directory location?
One reason could be the version of .NET framework (on IIS or application pool level) is different from the application one.
Another reason could be if there are modules used in your web.config which the current configuration of IIS doesn't recognize. E.g. URL rewrite or other optional modules, which you have to explicitly enable before using.
This can be a reason:
If there is no Web.config file in the
UNC directory, IIS 7.0 uses the rules
that are defined for the parent
directory. For the Web content to be
served in this scenario, the
worker-process identity must have
access to the whole content directory.
Otherwise, the Web request is
rejected.
Details here.
You need to set permission for your Website folder or copy them to wwwroot folder.
If you choose to set permission, there are two ways:
Right click on Your Website folder, or
Right click to Your Website in IIS
Then select Edit permission and Add a permission (IUSR - default iis user)

Url Routing is not working on IIS 6

Url Routing is not working on IIS 6. (using System.Web.Routing Namespace)
If i am running through VS 2008 then its working fine.
if i made virtual directory on IIS 6 then its not working.
its giving error 404 - file not found...
Thanks
By default, only files with extensions that are associated with ASP.NET (.aspx, .ashx etc) are sent to ASP.NET. You need to enable wildcard mapping to make sure that URLs to folders are processed (and thereby, routed) by ASP.NET:
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/5c5ae5e0-f4f9-44b0-a743-f4c3a5ff68ec.mspx?mfr=true

Resources