ASP.NET MVC RequireHttps Page Not Found - asp.net-mvc

I am trying to add the RequireHttps tag to a controller action but when I try to navigate to it I get a page not found error when I try:
https://localhost/MVCDemo3_4/Home/Index2
or
http://localhost/MVCDemo3_4/Home/Index2
The Http one tries to redirect to HTTPS but then the HTTPS can't find the page.

It depends more on how this is being hosted than the MVC attribute. If it's running off of a real IIS (or other full httpd) server on locahost, then you just need to make sure IIS is listening on both 80 and 443 (as #Jester mentioned, check the bindings). However, if you are using IIS Express via Visual Studio, then you really can only listen on one port and your debugging needs to be either all non-SSL or all SSL. This is controlled through the propeties on the Web project. Look at the Project URL field.

Related

Remove the custom port number from https url using IIS

I have a site which is configured in IIS7. Currently, the site named Site1, which uses the https protocol with a custom port number 5001. I can access this site by using the url given below:
https://demo.mydomain.com:5001/Site1
I need to eliminate the port number from the url, but it should access the same content which is used by the url "https://demo.mydomain.com:5001/Site1".
Expected result should be like this: "https://demo.mydomain.com/Site1"
Any help is much appreciated.
In IIS Manager, click on the Site (left pane) and the click Bindings (right pane). You'll see a binding for port 5001. Edit that binding to be port 443. (https://learn.microsoft.com/en-us/iis/configuration/system.applicationhost/sites/site/bindings/binding)
My guess though is you have some other site that is bound to port 443, if that is the case you either need to remove it from the other site, or if you need them to coexist, you need to dig into SNI which is a bit more advanced topic (SNI and SSL on IIS 8.5)

asp.net core RC2 iis hosting

I have hosted asp.net core app in IIS on window server 2012 R2 Standard. My site works fine when I use localhost based URL on the machine but when I try to access the URL using host name/machine name from network computer it does not work. What do I need to do to make it accessible from other computers?
There can be different reason for this:
Check your firewall to make sure your port 80 is open.
Check that the hostname point to the IP URL of your server.
What is the http code returned by the it does not work?
Tool:
Enter the Domain and IP, make sure they point to the same place.
http://www.hcidata.info/host2ip.htm
If firewall isn't the problem, and the site works via localhost on the server, make sure your IIS bindings are correct. Right click site, edit bindings, verify the domain / ip / etc match how you're trying to access it.

How do you force IIS Express to default to https URL?

I have enabled SSL in my MVC website for IIS Express by setting 'Enable SSL' in the project properties to true. So now I can access my site while debugging over http as well as https (IIS Express's default port 44300). However I'd like to force the default URL to be the SSL one. https://localhost:44300/. Whenever I run the app. from VS it always loads the http URL.
If I try and update the project URL (right click on the project -> click on properties -> navigate to the web tab -> set project URL to https://localhost:44300/) to https, the website fails to load. I just get a 'Page could not be loaded' error in the browser. However if I explicitly add a binding for https to port 44300 in my local IIS instance using IIS Management service it seems to work. I don't think I should have to touch local IIS in any way though.
Am I missing something here? Could someone help me figure this out?
The core of this seems to be finding the applicationhost.config file being passed to IIS, find the section like
<bindings>
<binding protocol="http" bindingInformation="*:62858:localhost" />
and change http to https
If you're using the Rider IDE, open the project properties (right click on solution explorer's icon for the project).
Make sure you add a port number for "SSL" and switch the Url from http://... to https://...
The port must be between 44300 and 44398, otherwise you'll get a connection reset error (see https://stackoverflow.com/a/24957146/423033 )
Sudeep,
If you are using the IIS on your machine (or on your server) you could create a rewrite rule that would intercept any http requests and will replace the http protocol with https.
Here is a link to get you started: http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module
As for IIS Express, it has its advantages of using it, but on the other side it is missing advanced functionality like URL Rewrite (check this link: http://weblogs.asp.net/scottgu/introducing-iis-express).
Best Regards,
Daniel D.
Figured it out. This tutorial is perfect and walks you through the whole process
http://www.lansweeper.com/kb/54/How-to-configure-SSL-in-IIS-Express.html

MVC site deployed to IIS 7 Homepage work All other page 404

I'm trying to deploy a MVC 3 site to IIS 7.5. The deafult route works but all links return a 404 error including if I manually enter the link for the homepage.
Details:
MVC 3 to IIS 7.5
Windows Server 2008 R2
MVC 3 is installed on server
Default Web Site/PaedPhysiotherapy_Uat
.net 4 is installed
DeafultApplicationPool used
App pool is .net4 and running in integrated mode
Custom error are turned off
If I deploy to a new website on the same IIS box using different ports, e.g. "http://newsite:81 which not under the default website everything works fine.
Even in the absence of routing, IIS will redirect requests for "/" to "/Default.aspx". In an MVC app, there's a Default.aspx which manually finds the MVC handler and invokes it. So that's probably why your home link works.
Your other pages must go through routing. In integrated mode there must be an IIS handler for this. Check the ExtensionlessUrlHandler in the IIS handler mappings. Compare that and other handlers with the sites which work.
At a guess, if this works when deploying to the root of a site then it looks like an absolute path has sneaked in. Perhaps somewhere this is a missing ~ in front of a path e.g.
/MyController
instead of
~/MyController
Also, you did remember to convert /PaedPhysiotherapy_Uat to an application?

Views does not open in live MVC application

After I published my application none of links works in web site except default.aspx. When I clicked them "page not found" is shown. I guess, it is about routing. But I did not do any change on default mvc routing settings. What could cause this kind of thing?
Thanks.
Verify that IIS which hosts your published web site has all the correct settings to run ASP.NET MVC (see this for on how to set up IIS 6 and this for IIS 7).
One would need more details to debug the issue. On a quicker note, first check for server logs (IIS/Apache) - it would indicate whether the request reached the server or not, where was the requested routed to, who processed it and what happened. Also check for server error logs.

Resources