ASP.net MVC HomeController URL - asp.net-mvc

By default the MVC Preview 5 web project comes with a HomeController.vb class. This sets the web URL to http://www.mywebsite.com/home/ by default. If I just wanted this to be http://www.mywebsite.com/ by default, how would I accomplish that?

Answered already so I'm just going to direct you to How do I get rid of Home in ASP.Net MVC?.
Users with 10k+ rep can also refer to https://stackoverflow.com/questions/33861/aspnet-mvc-routing-basics-root-route (deleted)

I'm not sure I understand your question, if what you want is to go to http://www.mywebsite.com/ and not have it be trailed by /home, that is the behavior you will get.
Is there something else you were looking for?

Related

How to add second application to MVC website

Say I've got an MVC website, www.codesmurf.com for example, set up with default ASP.NET MVC routing, nothing fancy. So my BlogController can be found at www.codesmurf.com/blog, and my FAQ similarly at www.codesmurf.com/faq.
Now if I also have a small survey project, currently in a different solution, how would I achieve to access this survey at www.codesmurf.com/survey?
What changes would I have to make to my routing and/or project structure to achieve this? So the entire survey project would be at the controller level of the main website, judging by the uri.
Do I have to achieve this using Areas? Do I need to create a SurveyController on the main site to redirect internally? Do I need to host this website separately and redirect externally? Any IIS configurations? How do I make sure my old routing isn't messed up?
This seemed like an easy task in my head at first, but I really have no clue what the best way to achieve this would be, and questions keep popping up in my head the more I think about it.
Note that the survey site is also an MVC project with its own controllers etc..
I haven't had much experience with changing the MVC routes, but would like to understand what I'm doing as well, so context/explanation would be greatly appreciated.
I personally would add the survey functionality as a service reference to your current MVC project.
Add Areas/Survey to your current MVC project and then start using the code from the service reference as you build up the Survey area.
When adding areas, all you will need to do is add some more rules to your map routes.
routes.MapRoute("areaRoute", "{area:exists}/{controller=Home}/{action=Index}/{id?}");

ASP.NET MVC getting calling URL

In an ASP.NET MVC 4 application, I would like to get the URL of the site calling the application. That is, I would like to be able to change the web site slightly depending upon which URL it is called from, and as such need to know how to tell what the calling URL is? I would then call a different index.cshtml file depending on which site it is called from.
Any help would be appreciated
I'm not completely sure what you want to do, but would this do the trick for you:
Request.UrlReferrer
Or
Request.ServerVariables["HTTP_Referer"]
Although I'd prefer the first one.

ASP.NET MVC generate subdomain URL in View

How do I generate a subdomain URL in the view? For ex, My application is on www.lol.com, which could change sometime in the near future. I want to link to email on google apps located on the subdomain mail.lol.com.
How do I accomplish this so I dont have to hardcode an absolute URL?
ASP.NET MVC isn't going to handle this for you.
Luckily, you're not the first one to want to do something like this. Since you have full control over routing in .NET MVC, you just have to customize something for yourself.
If you want something simple that will take out the www and replace it with mail (or append mail if there is no www), then you can check out the Request.Headers["host"] value and modify it as necessary.
If you actually want something flexible to handle the routing for you then you could check out this post on how to get started:
Hanssens.org | ASP.NET MVC Subdomain Routing
You can check Request.Headers["Host"] to find the current hostname.
You may want to strip out the www., if present.

ASP.NET MVC Url Masking/Rewriting

Let us say I have a url of subdomain.domain.com. Is there a way in ASP.NET MVC to have a url of say otherdomain.com/gotothesubdomain that takes you to subdomain.domain.com? I know that a simple redirect could do it, but I want the url to stay as otherdomain.com/gotothesubdomain.
Any advice would be greatly appreciated and thanks!
Assuming that you have 2 separate applications then you would need to grab the page as a string and then render it, here are some potential starting points - WebRequest/WebResponse, Html.RenderPartial in the mvc source or you could have a look at JoeyB's article.
It may be helpful to look at Luke Sampsons article that explains how to have multiple sub-domains in one mvc application, may help with your scenario?

How to handle stackoverflow's question urls in an asp.net mvc controller?

I would like to know how to set up the routing in asp.net mvc so I can have similar urls to stackoverflows question urls?
Do you believe that ASP.Net MVC is ready for production?
I am guessing that for url creation there is a helper class that creates the question urls.
The part i am wondering is how this is implemented on the Controller side. I think that most probably the home controller has a questions action and the id is 115634. Then comes the title of the question - I guess this is for search engine optimization. My problem is how the controller method signature would look like.
Is it a Question(int? id) or Question(string? param) that contains both the id and the title?
How would one implement this?
Check out this question where Jeff Atwood himself posts the code they use to make the friendly URL. Also, I am not a C# developer so I am not sure how things work on ASP.NET MVC, but if you try and remove the title in a StackOverflow URL, the page works anyways. They are 100% for readability for humans (so they know what to expect when they see the link) and for search engines. As such I would expect if you want something similar you make it an optional param in the controller.
check out this question...may be the answer you're looking for (:

Resources