How to remove directory name from url with global.asax code - model-view-controller

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.

Related

Laravel SPA (laravel + vuejs + sanctum) deployed in subdomain returns wrong api

I have this problem since several days.
I'm developing a Vuejs/laravel app, using Sanctum as an authenticator. where laravel mainly have the api gestion role, and I've started to deploying it. On Local, everything looks fine, api and auth are working.
On deploy, since my app is binded to be in a subdomain (laravelapp.maindomain with folder path of domain/laravelapp), when i try to access any page (vue-router) instead of domain/laravelapp/login i get domain/login, even if the page itself is looking fine.
If i try to reload the redirected page (domain/page) i have a 404. Also, since every API is pointing to domain/api/link instead of domain/laravelapp/api/link, everything is broken starting with auth.
I've tried modifying .env file, RouteServiceProvider, .htaccess(but i have no knowledge about that).
I also tried to set the subdomain Document Root to domain/laravelapp (it's the first thing i've done), but not only it dosn't work, if I try to print on screen subdomain's root, it returns domain. It's becoming a real issue right now, thank you for any help.
EDIT: I've discovered something. in the main domain there is a Joomla application. The api route contains the Joomla redirect (like, there is a plugin oh the site that changes language automatically, appending /en /it /de given the chosen language). So, in my case, the api is domain/index.php/en/subdomain. I tried again being more specific with document root, with no results, and playing around with .htaccess, but with no success.

WebAPI - Attribute routing to remove virtual directory from URL

I am using WebAPI 2 with Attribute routing in my project. I deployed my project under a virtual directory in IIS. I need to remove virtual Directory name from the URL.
Now my URL is api.mydomain.com/virtualdirectory/{controllerName}/{Version}
In my Route Prefix I am passing controllerName/Version.
I need to change the URL to
api.mydomain.com/{controllerName}/{Version}
Please help me how can i achieve this using attribute routing.
The question is will a request like api.mydomain.com/{controllerName}/{Version} hit your action?...route templates(with conventional or attribute routing) are always relative to the base path of your application and if the base path of the application includes the virtual directory, then the request urls would need to have this information to hit the actions...one option i can think of is to host your application directly under the website...

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