IISExpress - Get the site to identify its own SSL port binding - asp.net

OK, so a little background on the environment configuration at present:
Using VS2017
IISExpress folder present in my documents folder with applicationhost.config file
When I run my web project in VS2017, it runs successfully through IISExpress. If I view the IISExpress config window then it shows me that my app is running successfully and that it's using the config from my source\repos folder and not the main IISExpress folder in my documents. If I look at the config file in the IISExpress folder there is no mention of the bindings for my currently running application (makes sense, as it apparently uses a different config file).
However, within my app I need to be able to use the Microsoft.Web.Administration toolset to try and identify the port bound to https for the current site to handle a redirect to a page that must be secure. In the production environment this is just handled by pushing to https:// because we know an SSL certificate will be present. But, when debugging locally I need to switch to SSL and take the port number otherwise my redirect is broken, for obvious reasons.
Using _Manager_ServerManager As New ServerManager
For Each _Loop_Binding As Binding In _Manager_ServerManager.Sites(System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName()).Bindings
If (_Loop_Binding.IsIPPortHostBinding) AndAlso (_Loop_Binding.Protocol.ToLower() = "https") Then Return _Loop_Binding.EndPoint.Port
Next
End Using
The code above causes an error when running, as the current site does not exist within _Manager_ServerManager.Sites. If I inspect this property then I can only see the applications that are configured in the configuration file taken from the IISExpress folder in my documents, not the current site!
I'm really scratching my head on this one, is there any way programmatically that I can get this information for the currently running website?!
EDIT
Based on some of the comments below, more clarity has been requested as to what I'm actually trying to achieve. The website typically operates on standard HTTP, however, when progressing to one particular page for security reasons we need to shift to HTTPS:
Response.Redirect("https://" & Request.Url.DnsSafeHost & "/my-page.aspx")
When debugging this website locally, using IISExpress, this results in you being redirected to https://localhost/my-page.aspx, which is incorrect because the site runs on a port of localhost (i.e. http://localhost:64905 and https://localhost:64906). This means that I cannot just append Request.Url.Port onto the end of DnsSafeHost, because it will not be the HTTPS port required. Thus, so that we can run this project locally on our dev machines we need to automatically switch the port to the HTTPS version so that we can continue seamlessly without any disruption and having to manually rebuild the URL each time we get redirected.

Related

Host ASP.Net MVC Site

I've created a site using ASP.Net MVC that is meant to be stored on a local machine at my place of work. The intention is to have the site stored on this machine, but then accessible by all the other machines within this building.
I've followed Microsoft's tutorial as well as Code Project's tutorial, but I am not having very much luck. The binding is just the localhost, port 80, with * for the IP address. The URL is localhost/GrantTracker.
I've opened the ports within the firewall, checked the permissions on the directory (which is just within wwwroot), tried having the site take the place of the default IIS site (as Microsoft tutorial has you do) and tried having the site stand on its own with its own port (per Code Projects tutorial).
On the host machine I am receiving the standard "This site can't be reached, localhost refused to connect" which feels like either a port or permissions problem. I must be missing a step, but I can't seem to find what it would be. I am new to hosting sites through IIS so forgive me if I am just missing something basic.
I find it a bit strange too because my project uses Windows Authentication and when the site is first visited it performs that initial check with the user, authenticates, but then throws me the error.
Anyone have any ideas? Thanks in advance.
start simple,
create a simple html page, create an IIS application for it, on port 80.
Check and make sure you can see that page from another computer using the internal IP address of the the host machine so something like:
http:\\192.168.0.3\hostapp\test.html .
You can see the proper URL by running it from IIS, this will give you the entire URL you need, with localhost then just replace localhost with the IP address of the host machine to see it on other machines.
Do this in the original IIS folder so you don't encounter any folder permission issues. If you choose another folder you'll have to give access to the Network Service user ( i think, can't remember now, but there is a specific user that needs access to the folder where the website is deployed )
if you can see the page then deploy a proper website and do the same thing. Make sure the app pool is created correctly and it's up and running, then access it again on other computers and it should work.
Port 80 should be open by default so that should not be an issue.

Why am I getting a redirection loop from PHP built-in web server on AWS Cloud9?

This is my first attempt to migrate a project from Cloud9 to AWS Cloud9 since the clock is ticking.
I have created a brand new environment on AWS Cloud9, which is supposed to work out of the box. I've uploaded WordPress files and database, replaced URLs with my environment's preview URL (https://*.vfs.cloud9.eu-west-1.amazonaws.com), then ran the build with a PHP (built-in web server) runner.
Usually, that's all that is needed to migrate a WordPress website but this time I am stuck in a redirection loop whenever I try to preview the site.
My findings so far are that it's all down to forced SSL by AWS Cloud9. They specifically said they won't allow for any environment to work over a non-secure connection.
When I set the home_url in the options table to "http://...", then the loop breaks and the site appears. Of course, assets don't load because of the insecure connection. However, when I switch back to https in the home_url value, I am back in the loop...
No matter what I put in .htaccess, it doesn't help. I can't even find where to config Apache as the default /etc/httpd/conf.d/httpd.conf refers to /var/www directory, where as AWS C9's default workspace dir is /home/ec2-user/environment.
Below is a screenshot of my console while it's stuck in the loop. It does numerous connection to itself (duh..) and finally terminates.

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

asp.net waiting for localhost forever

Suddenly this morning I turned on my computer and launched visual studio... And no matter what I tried and whether I run or debug, and whatever the browser is ( chrome / firefox / IE 11 ) it is waiting for localhost forever.
If I deploy it to azure, by just checking in ( continuous integration ) it works like a charm
I've read both:
Waiting for localhost, forever!
How to figure out why my local host site takes so long to load?
As I write, it has been waiting for localhost for more than 15mins. I restarted VS, even rebooted the computer... tried the ipv6 disable stuff on firefox...etc
I noted ( do not know if it is useful ) that Replacing localhost by 127.0.0.1 throws:
Bad Request - Invalid Hostname
HTTP Error 400. The request hostname is invalid.
also my C:\Windows\System32\drivers\etc\hosts ( unchanged )
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
Any idea ? I've not been able to show a single localhost page in 3hours.
Check firewall for blocked ports, change dynamic ports of application to some fixed port.
I had a similar issue where my site got "Waiting for" forever. Tried restarting the website and nothing.
I was not able to reboot the machine (I am pretty sure that it would solve) so I kept investigating what could be.
I found out that, in my case, the solution was to change the "Application Pool" of the website. It appears that the current one crashed or something like that (I was able to stop it but not start it back again), so I created a new Application Pool and the site started working again.
Okay, I've found that this happens (on a server) when you've hardened security properly.
For example, you no longer blanket apply IIS_IUSRS to the wwwroot but setup proper accounts for each App Pool and are setting the NTFS perms properly.
The problem is that the worker process/ASP.NET wants to enumerate the files in the folders "leading up to" your website root. I think it wants to look for web.config files etc.
The failure to produce an error, i.e. the infinite loading is a bug in my opinion.
e.g. i:\wwwroot\project\virtual\base
You'll need to apply IIS_IUSRS group read access to wwwroot, project, virtual but not base. The trick is to only apply to the current folder, i.e. don't apply to subfolders and files.
Apply read rights just to the worker process/AppPool identity to the base folder.
If IIS_IUSRS has read rights to the whole tree, then all worker processes will have read access to all other website base folders and contents, such that a compromised site will be able to access data/config in other sites.
Sometime it happens due to issue with symbols loading.
Try this
Go to Tools -> Options -> Debugging -> Symbols and click the button 'Empty Symbols Cache'
In my case there was a problem with configuration of Visual Studio stored in /.vs folder inside solution directory.
During development a lot of changes were made in IIS configuration: creating new sites, replacing old ones, changing pools etc. So Visual Studio have lost "connection" to given site and its pool. After deleting of /.vs folder and launching of Visual Studio the new execution configuration was created and it was properly attached to current IIS configuration.
Restarting the IIS may work as it will end the current instance and run your web page in a new instance.
I had received a project where the webconfig had port number mentioned along with the server like this.
sqlConnectionString="Data Source=<<SQLInstanceName>>\SQLEXPRESS,<<Port>>;Initial Catalog=<<DBName>>;Integrated Security=false;User Id=<<UserName>>;PWD=<<Password>>;"
After removing the port number from connection string, the error message disappeared and code began to work.
sqlConnectionString="Data Source=<<SQLInstanceName>>\SQLEXPRESS;Initial Catalog=<<DBName>>;Integrated Security=false;User Id=<<UserName>>;PWD=<<Password>>;"
I am relative new to ASP.net. Dont know if this is going to cause problem elsewhere (^_^).
My issue was a result of a not having proper credentials on the working website folder. If you arent sure grant full control to the folder as a test. User = IIS AppPool[app pool name]
For me, on aspnet core it was a problem in Configure() method hanging because of exception
In my case, the problem was that IIS didn't have sufficient permissions to the website.
I fixed it by granting Full Access permission to the IIS_IUSRS user on my entire website code folder (as in yoursolutionfolder\yourwebsiteprojectfolder).
Then after granting permissions, I had to run iisreset for it to start working.
I was Able to Connect to Application when asp.net waiting for <...> modal appear then i Click Browse in my IIS
note : You must create the Application Pool and Website manually and set the website pool to Application pool that you have been created before.
Please check WEB.CONFIG file, I had a similar issue where my site got "Waiting for" forever. Tried restarting the website, laptop nothing happened, it was prompting me for SQLServerExpress, I realized that the database server was not correct on my web.config so I changed it to the correct one which resolved my issue
In our case, the issue was Symantec Endpoint Protection. By turning off the Enable Network Intrusion Prevention option on the Network and Host Exploit Mitigation module, Localhost was working again.

ASP.NET and IIS 7.5 - HTTP Error 403.14 - Forbidden

I try to configure IIS 7.5 on a new server (Windows Server 2008 R2), in order to run an ASP.NET 4.0 application. Two "domains" are defined on the server (managed with Parallels Plesk), each one appearing as a site in IIS. One domain is for the public site, the other is used for tests. At the present time, the DNS of the test site points to that new server while the DNS of the public site still points to our old server. We transfer the test site first, to see if everything is OK, before transfering the public site to the new server.
Pointing to the test site in IIS, if I run the Browse command on the folder of the application, I get the HTTP Error 403.14, with the message: The Web server is configured to not list the contents of this directory. The strange thing is this: if I put the exact same folder structure in the other domain on the same server, and I run the same Browse command, I see the default page of the application (I don't know if everything works after that but, at least, the first page shows up as expected). I should add:
Both sites use the same application pool.
Both sites have the same permissions (I checked one by one, also compared with cacls)
The default page is not set in IIS but is the authentication form specified in Web.config
So, same setup but different results. I don't know if there is something else that I should check. I am on very shaky ground when I talk about server configuration and IIS; so I hope that this description is clear enough and makes sense.
I think I found it. It probably doesn't work for both sites on the new server. When I run the Browse command, it shows the page in IE using the DNS of the site. Since the DNS of the public site still points to the old server, the page displayed in IE is not from the folder that I clicked, but rather from the old server site.
I can now look for standard solutions to the 403.14 problem on the new server...

Resources