Can MVC3 perform the job of IIS URL Rewrite module for my Angular6 App - asp.net-mvc-3

I am working on an Angular (6) app which sits within an existing MVC3 application. I.e. /MVC/App is my angular app. I have configured it using IIS Url Rewrite so that any request to "/Mvc/App" is forwarded to index.html page, just as described here, to make sure angular routing works:
https://blog.angularindepth.com/deploy-an-angular-application-to-iis-60a0897742e7
It all works, but it poses a requirement for existing clients that they will have to install IIS Rewrite Module as a prerequisite. So I am looking for an alternative and since we already have MVC3 I wanted to know if it is possible to achieve this using MVC3 routing.
Can we achieve what the IIS ReWrite is doing here to ensure that all requests are served up to the Index.html page with the child routes so that angular routing works as expected?

I achieved this by creating a controller with action and a routemap that maps any route starting with /Mvc/app to that action as below:
context.MapRoute(
"AngularAppRoute",
"app/{*pathInfo}",
new { controller = "SpaApp", action = "Index", pathInfo = "" }
);
I had to make sure that the Index action's view does not have any master page and it's content was set to the same as the Index.html file generated by ng-build.

Related

ngnix - rewrite url based on path

I have my next.js app working on http://testdomain.amazonaws.com:443/abc.
Using ngnix configuration, I would like to have https://anotherdomain.com/abc to render my app at http://testdomain.amazonaws.com:443/abc without changing the url in the address bar and also it should take the routes from the next.js app keeping the https://anotherdomain.com.
That is, if user clicks on other links and navigates to other routes like
http://testdomain.amazonaws.com:443/abc/pqr/1 it should become https://anotherdomain.com/abc/pqr/1 in the url.
Can anyone help me understand if we can write a rewrite rule to achieve this in ngnix?

How to remove directory name from url with global.asax code

I am using MVC routing in asp.net Web forms and I want to remove the folder/directory name appended in the URL. Locally this works fine but I have the following address now appearing on Godaddy shared hosting.
www.mywebsite.com/my-folder/contact
but I want like this
www.mywebsite.com/contact
I have tried web.config techniques but no success that's why I am asking is there any way to redirect this using Global.asax.

Loading an MVC site

Hello I am in desperate need of help. I just created an MVC site made in Visual Web Developer 2010
and each time and on different Web Hosts I get --Index of /-- instead of the site loading properly. It's as if the server or browser is looking for an 'index' file instead of being routed through the MVC folders to the proper start up page. I've done everything I believe I am suppose to do as far bring all my dll 'system' files to the 'bin' folder as well as everything else including getting a Web Host that has MVC supporting server but I still keep getting 'Index of /' and the folders instead of the site. Can anyone help? I'm really in a spot. I've been working on this site for months and I need to get it up and running.
Thanks, Rob
It looks like your default route is not setup or the setup is pointed to a place that doesn't exist. Your default route will be in the default.asax.cs page (MVC4 is App_Start/RouteConfig.cs) and looks something like this:
routes.MapRoute(
"Default", // Route name
"", // URL with parameters
new { controller = "Home", action = "Index"} // Parameter defaults
);
So the the Default action is Home/Index. You can change this if you want to redirect to a different default page.

Deployment of ASP.NET MVC3 application on IIS V6 is not directing to the desired controller action

In VS2010 ,I published my asp.net mvc3 web application as a file system and on IIS Manager, I created a new virtual directory(file system) and created a new website. But browsing the website is not redirecting me to the desired controller action. Can anyone suggest where i am going wrong?
IIS6 doesn't support extensionless urls by default. You will have to configure a wildcard mapping if you want to use such urls. Otherwise you will need to modify your routing in order to append an extension in all your urls that is associated with the aspnet_isapi filter in IIS.
Here's a guide that you may checkout: ASP.NET MVC 3 Extensionless URLs on IIS 6

MVC Routing / HostHeader does not work when I use RequireHttps

I'm currently experiencing an issue whereby my MVC site is not responding correctly using IIS 6.
I've setup a url as http://mysite.co.uk which automatically redirects to the correct MVC home page. As the site contains sensitive information I have added the [RequireHttps] attribute to each controller class to automatically redirect the browser to an https url of https://mysite.co.uk which works correctly.
When I access the site as http://www.mysite.co.uk the site correctly redirects to https://www.mysite.co.uk/Default.aspx but it then responds with
Bad Request (Invalid Hostname)
It looks like any time I use www. as part of the url it fails to respond but I have a hostheader setup as www.mysite.co.uk under the IIS website. Is there anything in particular I need to do to make MVC understand the www. part of the url in terms of routing?
Thanks,
Brian.
IIS 6 doesn't add ssl host headers as you think it would. see my article at:
http://completedevelopment.blogspot.com/2009/06/multiple-host-headers-ssl-and-wcf.html

Resources