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

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

Related

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.

Published website ASP.NET with IIS

I have just completed my website and I started working with IIS it works fine when I put all my file without published. I copy the whole website to wwwroot inside my folder as I said It works fine but when I tried to work without code behind page it didn't work I published website from VS. and I copy my published file to the same folder but it doesn't work.
I received this error:
Eval is not declared. It may be inaccessible due to its protection level.
I don't want to put my code behind page. How can I run my published pages?
First, when you publish your web project, their are no code behind pages.
Do this, set a directory and publish your site in it.
Now cmd-> intemgr->
site-> -> add web site->
give site name and select an application pool, then set the physical path to the directory where your application is published, if necessary change the port to something like 50 because 80 is a standard port for http. Hit ok. Your site is ready.
Please check in application pool that your application pool is set to .Net framework version V4.0 (i mean the version compatible to your app ).
just click to browser the site, please do check the uri you can see the port number also

Changing "Project Url" causes ASP.Net Web app to not be debuggable

I have an ASP.NET Web Application project that I am using to host a WCF Data Services (OData) project.
I went and changed the url from:
http://localhost/MyProject
to
http://localhost/v1/MyProject
after I did that I created a Virtual Directory for the new project URL.
Now when I run I get this error:
Unable to start debugging on the web server. The web server is not configured correctly. See help for common configuration errors. Running the web page outside of the debugger may provide further information.
I clicked help but it was no help (was IIS 6 level instructions, I have IIS 7). I did some googling and it was all fairly generic responses.
How can I get this working again? (Aside from revert to my old Url. Reverting works but I changed it for a very good reason.)
Your virtual directory need to point to the same scr directory you were originally debugging against.
Also, make sure the virtual directory is configured for Windows Authentication, which is required for debugging.
I had to go to my website in IIS and add a folder under it called v1. After I did that it all worked perfectly.

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.

IIS 6.0 web application - Does the entire "website" need to be an "application"?

I had a website hosted in IIS. One small section of it needed asp.net. So I just right-clicked that section/directory and made it an application and a virtual directory.
Is that alright? Or does the entire "website" need to be made into an application and virtual directory?
The reason I ask is that when I try to browse to the aspx page in this "application", I am getting a parser error message "Could not load type...MyCodeBehindType" in the page directive, which seems to me to indicate that it is not finding the dll's, or even the code behind class files (which are clearly in the same directory).
EDIT:
If I do it this way, with only a subfolder of my website actually being a web application, where do I put the dlls? In a bin folder of the website the web application is within? Or in a bin folder of the web application?
Making just a folder within a website, an application, should be fine. I usually have to remember to change the version of ASP.NET from 1.1 to 2.x, that may be what's causing the error.
In order to test the configuration, start with a blank test page (blank.aspx) with just HTML. If the HTML shows up, you know IIS is serving .NET pages.
If there is a problem with ASP.NET not being correctly registered for IIS, you could try re-registering it. Open the following folder:
%WindowsDir%\Microsoft.NET\Framework\x.x.x\
and run:
aspnet_regiis.exe -i

Resources