MVC 4 Web Api Route 404 issue - iis

I have a plain-vanilla MVC 4 Web Api project created using VS2012.
The (/api/Values) works out-of-the-box on the localhost but NOT when deployed on IIS (packages created using the standard "Publish..." from the project menu).
After been through lot of articles and reading suggestion for similar issue I found the Route tester which visualized how IIS was interpreting the request.
As the screenshot revels, the IIS is interpreting ~/api/values as ~/api/values.aspx
Any input on why this is happening and suggestion on how to resolve it is highly appreciated.
Thanks a lot for the help.

Related

Deploying ASP.NET Core 6.0 MVC app to Server doesn't work

I am new to web development, I am learning it on the way as I develop my application.
I have an ASP.NET Core 6 MVC app that basically does this:
Starts with a Login
After login you can view the data
You can manipulate data on the view page
You can view some logs, and acknowledge them
So, my app works just fine when I run it from VS 2022.
I would like to deploy the app, so it can be used within the company. It all works on an internal network.
I have two options for deployment and to host the app from:
Windows Server 2019 (IIS)
Synology NAS
It really doesn't matter for me, but I have been through more than a dozen of tutorials/videos, but could not get it work either way.
I have tried different publishing methods.
I have .NET Core Hosting 7.0.2 and Web Deployment installed on the Windows server.
Basically my published file structure doesn't look like in some of the tutorials.
The furthest I've got is that I can load the page on the Windows Server 2019 machine, it shows the login page, but after I press "Login" it says ".../LoginController" Page not found.
So, after this chaos, can anyone give me some guidance where should I look for the solution? I thought it would be a good idea to use MVC, but now I think it would be much easier with a simple ASP Web app...
Eventually, after I got to the Login page (as I mentioned), I figured out the problem there. I am using cookies, which were set to "secure" in the program, but I was usint http instead of https. As a test, I have set the cookies' "Secure" property to "false", after that it worked.
At least I know where to go next.

How to get the application names hosted in IIS?

I have an application which is used to configure the applications under "Default Web Site" in IIS. Now i want to check whether all the applications are hosted in IIS successfully or not using C# code. Can anyone please guide me to get the application hosted name from IIS?
I have tried but no luck.
Thanks in advance!!!
Regards,
Karthi.
new System.DirectoryServices.DirectoryEntry("IIS://localhost/w3svc").Children
Since you are on IIS 7 and above, you can use Microsoft.Web.Administration,
http://www.iis.net/learn/develop/extending-the-management-ui/overview-of-mwa-and-mwm-for-iis
Besides, keep in mind the facts you should know,
https://blog.lextudio.com/2015/05/whats-microsoft-web-administration-and-the-horrible-facts-you-should-know/

Web API 2 project and MVC 5 Website project in same domain

Technologies used:
BreezeJS
OData
Web API 2
MVC 5
IDE: Visual Studio 2013
I've been wrestling with the idea of having a Web API project and a separate web site project in a single solution.
My Web API 2 project opens up as: localhost:2020/ExampleProject.API
My MVC 5 WebSite project opens up as: localhost:5050/ExampleProject.WebSite
Now by default web api doesn't allow cross origin policies. So I played around with enabling CORS in my Web API 2, although I was able to get it to work, it only works for the latest browsers; I need the backward compatibility of IE7 to IE9.
So I played around with JSONP. I'm not fond of the lack of support that exists for this. I was able to get it to work for my Web API 2 project, but it doesn't work if I wanted to use BreezeController if using the breezejs web api library. It also doesn't work if I wanted to create an ODataController.
So I'm moving away from the idea of cross origin sharing; though hoping that in the future there will be enough support for jsonp regardless if I use BreezeJS WebAPI helper or ODataControllers.
For now, I have no idea how to put my WebAPI project and my MVC 5 Website under the same domain where I can have:
localhost/ExampleProject.API
localhost/ExampleProject.WebSite
Do I have to make some configuration in my host file? if I want to run my projects from VS2013 would it be able to run both projects under the same domain.. or do I have to keep on manually changing the URL in the browser?
Well, the answer was really really simple.
I know this an old question, it was just that I forgot how to do it since it's been so long since I did this. Searching for the answers on google and on stackoverflow was difficult since the discussions talked about setting up cross origin policies instead of setting up a same origin policy.
I spent the good portion of my time putting everything on IIS.
Created a website and had it point to the physical path where my website csproj and bin folder is located. I gave it a hostname of "dev.example.com" and changed my hostfile for 127.0.0.1 to refer to dev.example.com
Created a Web Application for the website, and set it up for web api 2 project. Everything magically worked after that.
The dumb part was, I could have easily done this in visual studio. I remember in VS2010, this cause many problems, but in 2013, I guess bugs have been fixed and it works now.
I had my WebSite project set up as
localhost:2020/ExampleProject.WebSite (incorrect)
instead of
localhost:2020 (correct)
and created a virtual directory. I do this by right clicking the project, going to properties, under "Web" tab.
So basically, the rule of thumb was to get my website to be my main root domain, and to copy that full domain to any web application I want to add under it.
So: website would be:
localhost:2020
web application:
localhost:2020/ExampleProject.API

Sharepoint Connecting to TFS gives SSL error

i am trying to build a web part to display the TFS projects and i am using Microsoft.TeamFoundation.Framework.Client and using Microsoft.TeamFoundation.Framework.Common;
like here
This works perfectly in a sample web app , but the moment the code goes into a visual web part,
i get a SSL errors
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure...
Any help is appreciated
Thanks
Rajat
I never work with TFS interactiong with Sharepoint. Needless to say that I didn't came across such problem. But here is the link which explains in detail on how a aspx page can interacts with the TFS.
http://geekswithblogs.net/TarunArora/archive/2011/06/18/tfs-2010-sdk-connecting-to-tfs-2010-programmaticallyndashpart-1.aspx
Have Great Day!
I got TFS configured on my VM ,which solved my problem, but i was unable to solve the original issue .

Issues with requestValidationMode="2.0" and validateRequest="false"

I've been looking at this issue for quite a while now.
Basicly what the issue is that IIS 7.5 and IIS Express both ignore the following two lines:
I've googled and searched here on stackoverflow and most just suggest adding those two lines, but it does not matter what I do(reboot server, create a new app pool) it does not work.
Anyone got any ideas to why this happens?
you also need to add ValidateInput(false) to your action if you are dealing with MVC.
or add deriective on the page if you are working on web forms

Resources