How to use host headers in IIS for a web application? - asp.net

I have configured a website in IIS with a host header, so that I can call the url customhostheader/ and the website will be shown.
When I try to publish my web project, I get the error that some sections in web.config are registered as allowDefinition=MachineToApplication. But I cannot convert the website in to an application in IIS. I can only convert virtual directories into IIS applications, but I don't want the much longer url http://customhostheader/virtualdirectoryname, I prefer to have just http://customhostheader.
Any ideas what I could do?
Thanks.

Add an application with the name customhostheader which is pointing to your published code (parent of bin folder)
To do this
Right click on "Default Web Site" in IIS and select "Add
Application"
Give alias as customhostheader and provide the path to your application.
Edit based on the comment
Each website by default contains an application. So we just needs to make sure the path of the website is correct.
The following two points should be enough to set up the correct path
The path should be parent of bin folder
The web.config should be present on the path
The default document can be set through the IIS or web.config

Related

web.config application pool error after moving to new server

I have the following error after move my website from server to another server
I have already checked iis and make sure the app has an application pool and it points to the correct file path
here is a screenshot of my application pool
I even tried to add virtual directory and add application and still not working
Check siteMapFile attribute of sitemap
The possible reason behind the issue is:
When you create a new web application using visual studio.net, it automatically creates the virtual directory and configures it as an application. However, if you manually create the virtual directory and it is not configured as an application, then you will not be able to browse the application and may get the above error. The debug information you get as mentioned above, is applicable to this scenario. To resolve it, Right Click on the virtual directory - select properties and then click on "Create" next to the "Application" Label and the textbox. It will automatically create the "application" using the virtual directory's name. Now the application can be accessed.
When you have sub-directories in your application, you can have a web.config file for the sub-directory. However, there are certain properties that cannot be set in the web.config of the sub-directory such as authentication, session state (you may see that the error message shows the line number where the authentication or session-state is declared in the web.config of the sub-directory). The reason is, these settings cannot be overridden at the sub-directory level unless the sub-directory is also configured as an application (as mentioned in the above point). Mostly we have the practice of adding web.config in the sub-directory if we want to protect access to the sub-directory files (say, the directory is admin and we wish to protect the admin pages from unauthorized users). But actually, this can be achieved in the web.config at the application's root level itself, by specifying the location path tags and authorization.
in your case the site map section causing the issue. try to remove it from the config file.
You could refer this below link:
Nested ASP.NET 'application' within IIS inheriting parent config values?

How to create Application in the IIS Default Web Site root (virtual path : '/')?

Context
I have an Asp.Net MVC application. I would like to deploy it to an IIS (Windows Server 2016). I do not care which will be physical path, but I would like to access to the application in the virtual path '/'
(I am using Package web publish method, because no online access to the server, but I think this question is on IIS/ASP and not about publishing. I clearly miss some basic concept about IIS/ASP.)
What I've tried
1) When I try to create an Application in IIS then the dialog forces me to add an application Alias, which becomes the part of the virtual path. So regardless the physical path now the the url will be
myserver/myapp/mypage instead of myserver/mypage
which is not what I want. I would like to access to the page as myserver/mypage
2) If I simply deploy the app under wwwroot then it will appear as myserver/mypage it seems to be working, but where is the "Application" this case? (see picture).
Question
Maybe I missing something: Is this the Default Web Site is an "Application" in its own right? How to configure then its Application settings? If not, then how can I create an Application which's virtual path is '/'?
If I have understood your question correctly, you want to access the application as servername/pagename. In order to do so, do not create an "application" or "virtual directory" under a "website". Instead, directly host the content under Default website. You can change its path under "Basic Settings" and point it to your content folder.
You can also create another website at port 80 and point it to the location where your content is present. However, you will not be allowed to create 2 website with the same IP-port-hostname combination. You can solve this problem further in 3 ways.
If Default web site is not in use, then instead of creating another website, click on Default website, select basic setting from right hand panel and change the path to application content folder.
If Default website is in use, then create another another website at port 80 with a hostname.
If you do not have a hostname and are accessing the application using server-name, then you will have to modify the port to 8080 or something like that.
Refer my blog - https://blogs.msdn.microsoft.com/parvez/2016/07/27/iis-bindings/ for more information about IIS bindings

Why is a Web Site project not serving pages except through IIS?

I have inherited quite a complex web site project, and when I run it in VS 2012 under the default "Use default Web server" setting for "Server", it serves the login page correctly, under the base URL http://localhost:45632 and I can log in nicely. Then, when I click a menu item with the URL http://localhost:45632/Apps/Visitors/General.aspx, I get a good and plain 404.
If I then create a web site (not application under the default site) for it in IIS 7.5; set the physical directory to the project's source folder; give it a host name, xtjethro.local, and edit my hosts file to point that host name to 127.0.0.1; set the web site project to use a custom server, with a base URL of and finally, browse the site from its context menu, it serves its pages under the base url http://xtjethro.local/ instead of http://localhost:45632, everything works fine.
Then, if I set the web site project to use a custom server with a base URL of http://xtjethro.local, and restart VS2012, running it as administrator, everything works from there as well.
I would like to know why http://localhost:45632/Apps/Visitors/General.aspx doesn't work under VS2012, but http://xtjethro.local/Apps/Visitors/General.aspx does work under IIS.
The Visual Studio development web-server usually runs the site under a virtual directory which matches your project name. That would mean that the URL of your page should be http://localhost:45632/YourProjectName/Apps/Visitors/General.aspx. If you create an application under the default site in IIS, you will probably see the same problem.
You'll need to change the way your links are generated. Instead of using /Apps/..., use ~/Apps/... - ASP.NET will automatically resolve ~/ to the base path of the site.

Issue with Response.Redirect and Page.ResolveUrl in ASP.NET WebForms site hosted on Amazon AWS

I have deployed an ASP.NET WebForms site to Amazon AWS to the following link ('webapp' is just a dummy name I haven't included the real url)
http://webapp.elasticbeanstalk.com
My problem is that wherever I do a redirect using Response.Redirect (for example Response.Redirect('~/Page.aspx') or create a link using Page.ResolveUrl (for example Page.ResolveUrl('~/Page.aspx'), the url becomes
http://webapp.elasticbeanstalk.com/webapp_deploy/Page.aspx
But I want it to be simply:
http://webapp.elasticbeanstalk.com/Page.aspx
My guess is that the site is located in a folder called 'webapp_deploy' on the Amazon server and the home sign '~' gets mapped to 'webapp_deploy'.
Is this a known issue or am I doing something wrong ? Are there any workarounds to this...do I need to change something in the AWS console ?
Thanks
By default, your web application will be deployed to webappname_deploy, but you can change that in the Project Properties.
In the Solution Explorer, right-click on the web project and select "Properties".
In the properties pane, go to the "Package/Publish Web" tab.
On that tab, there is a form field labeled "IIS Web site/application name to use on the destination server:"
Remove webappname_deploy, so it would just say "Default Web Site/"
Your web app will then be deployed to the root of the IIS Default Web Site.

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)

Resources