asp mvc 3 home index page only loads ONCE - asp.net

I created an asp mvc 3 project using the default layout that comes with the non-empty application. Everything has worked great etc. Until I put it in IIS. I have a very strange issue. I can only go to page.com/ which is the HOME controller and Index view ONLY ONCE. When i first load the page i see it. But then when i click the home button it takes me to the account log on, and the url is messed up it looks like page.com/account/logon=?and a bunch of other information.
But on some other controller it does look good like page.com/Information/Shop
Anybody know what might be the home index issue?
Web.config looks like this
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

Are you using Named Pipes? .Net 4.0?
it could be that your home link is pointing to something different (whether thats www. or lack there of, or localhost/home rather than localhost) and this is causing the confusion in routing.

It is likely that the IIS site you deployed to has the webroot folder for your site set to require authentication. Thus, when you attempt to access the pages it requests you log in. Once logged in the users information should be maintained in the SessionState so you would not be required to login again during that session. Of course, once the session is ended (due to timeout or certain navigation events) the users informaiton is lost and you would need to log in again. The settings can typically changed in your web.config file. Here is a link to MSDN describing the authentication section.
http://msdn.microsoft.com/en-us/library/532aee0e.aspx

Related

Create a HotTowel site with login (facebook, twitter, google, microsoft)?

I am creating the site using the following steps.
Create a Asp.net Mvc 4 web application with standard "Internet
application" template. So the login code is created. Then update all
referenced code use NuGet.
Run Install-Package HotTowel and update all code using NeGet.
When I run the code.
It will go direct to the HotTowel HotTowel\index.cshtml instead of the page Home\Index.cshtml which has login code.
The generated html code of HotTowel\index.cshtml is wrapped in the generated html code of Shared\_Layout.cshtml.
What I want is
The site shows the login page first, and redirect to the HotTowel home page after logged in.
Update:
I tried to Install HotTowel on a pre-created built-in SPA project and got the similar issues.
Update 2:
I found that commenting out the following lines in the file HotTowelRouteConfig.cs will make sure the start page go to Home\Index.cshtml.
[assembly: WebActivator.PreApplicationStartMethod(
typeof(test4.App_Start.HotTowelRouteConfig), "RegisterHotTowelPreStart", Order = 2)]
in your global.asax you need to add new route
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Account", action = "Login", id = "" } // Parameter defaults
);
and your login ends on return Redirect("/"); or return RedirectToAction("HotTowel","index");
habe a look at DurandalAuth here is the live Demo you can clone it with mac.github or windows.github and review the code i hope this will help you

MVC3 Server Error in '/' Application

I'm not new to ASP.NET MVC but I have a really strange issue that I haven't been able to solve. I've checked most other related queries on SO and further afield but I haven't yet found a solution. I have a really simple ASP.NET MVC 3 application running under Cassini which was working fine until I added log4net logging. I've since removed all the references to log4net to try and get it back but I always get the error:
Server Error in '/' Application.
The resource cannot be found.
HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed blah...
This is the result, no matter which url is requested.
The application still has the original HomeController, Index.cshtml etc and the default route from the standard 'out-of-the-box' Visual Studio 2010 template.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
I've checked and double-checked that there is no file missing (e.g. a css or js file) thats required and another issue which prevents me from moving forward on this issue is that no breakpoints are hit when trying to debug it. In fact, if I put a breakpoint on the first line in the Application_Start method, and start debugging, the breakpoint is not hit at all and a second breakpoint appears (see the image below)!
This happens even if I do a clean and rebuild.
I've tried using Phil Haacks Route Debugger but still get the same error and the fact that the Application_Start breakpoint is not being hit makes me suspect my web.config. I've checked it several times and in fact replaced it with a web.config from my hosted site where the application is running ok, but still get the same result on my development setup.
I've checked there is no StartUp page in the properties.
I want to add some more functionality and be able to debug it before deploying to my hosted site but this is stopping me.
Has anyone come across breakpoints being added when you start debugging? Considering the symptoms, where would you start looking for the root of the problem?
Just solved it, so for those who might trip over this one, I've noted the reason why below. However, what might be of more value was my approach to find the issue in the face of no debugging or tracing available. As it is still a small site I decided to create another standard 'out-of-the-box' MVC 3 application and manually compare files. There appeared to be no difference between files but while going through this exercise I noticed that in the problem application, the Global.asax files were sitting in the Views folder! I must have inadvertantly moved them - it wasn't immediately obvious because the Views folder was always expanded and glancing at it, would appear that the Global.asax files were in the right place because they are normally immediately below the Views folder (just not indented as they are when inside the Views folder).
Anyway, problem caused by me but did cause some weird behaviour!

Maintaining old URLs after revamping ASP.NET web site

There is an ASP.NET 2.0 web site that I intend to migrate to a new web framework based on ASP.NET 4.0. While I know this involves manually preparing a script/program to transform site's content from old application's database schema to the new one, I am more concerned about preserving the old URL formats; mapping them to the new web engine's URL format.
I have not yet decided what is the most appropriate CMS engine to migrate towards (thus Web forms or MVC is still not clear). However, I'd like to draw on everybody's experience on
general issues to look out for (regardless of web application platform)
candidate strategies/techniques to handle the URL remapping in ASP.NET
Google Analytics is already configured for the web site, so there is a history of the most requested links to study - which are the most important URL formats to remap and which are not worth preserving.
Due to work areas i've been diverted to the past few years, I've not been able to keep up with the latest ASP.NET capabilities that can help with this. Oddly, I find little material discussing how to properly preserve old URLs; most web sites are pretty nasty in totally discarding their old links when they perform a design overhaul.
My first thought of the most straightforward technique is just to specify in web.config a custom 404 aspx page that will read the old requested URL (which will carry the original content ID). Based on the content ID, look up a custom database table to find the new content ID, and redirect with the new URL.
At this point I am unsure if I'd want to make use of URL rewriting HttpModule or extension because I'd only want to incur the "lookup" only when it becomes 404, rather than a check on each and every request. Knowing that old URL requests will eventually fade over time.
What other factors/aspects should I consider?
For SEO performance, it's not really a good idea to issue a 404 or a 302 if you want to maintain good link value for each page you should issue a 301, a permanent redirect which search engines will use to pass any link equity to the new url.
With MVC you could register your old urls to a route that uses some form of dedicated RedirectController, something like:
public class RedirectController : Controller
{
public ActionResult RedirectArticle(int articleId)
{
string newUrl = // do something to figure out the new url, e.g. http://localhost/article/1 -> http://localhost/1/my-custom-article-url
return RedirectPermanent(newUrl);
}
}
That way, you can register routes to support both the old infrastructure and the new, with a RedirectController issuing the appropriate page-specific 301 redirect to the new page.
routes.MapRoute(
"NewArticleUrl",
"/{articleId}/{articleTitle}",
new { controller = "Article", action = "Display");
routes.MapRoute(
"OldArticleUrl",
"/article/{articleId}.aspx",
new { controller = "Redirect", action = "RedirectArtciel" });

ASP .net MVC Invoking default controller and action vs Setting a startup page

I am developing code on the sample ASP .net MVC template provided by VS2010. The first time I ran the code without adding anything, the index.aspx page was invoked which is expected. But for some reasons I added a login.aspx and then accidentally set that as a startup page. Now when I ran the application the default startup url look like http://localhost/Views/login.aspx. I am thinking this is not a valid MVC routing path and I get the requested resource cannot be found error.
I am not sure how to revert this back and make sure the default ../home/index is invoked. Can any one throw some light on this? Also should I not set the startup page as we do in asp .net webforms?
Short answer: You have done something that you are allowed to do in ASP.NET WebForms but it doesn't work the same in ASP.NET MVC. To revert what you have done, please open project properties (From Project Menu) and go to the "Web" tab. Set the Start Action to Current Page instead of Specific Page. Now when you run your project, you will be able to see the Home/Index page as before.
To do it properly in MVC, you need to configure the route in Global.asax. You will find an entry similar to the following:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
You can see that that when you don't specify a controller and action, it goes to Home/Index. You can change the controller name and action name there and it will default to the action you have mentioned there. Just make sure that you have the relevant action in the controller that you have specified there.

ASP.NET WebForms and MVC Hybrid - Strange characters in URL (random stuff)

I am in the process of creating a hybrid webforms / mvc app. It all works find in VS with its debug web server. However, after overcoming numerous other issues and I am now stuck with a od problem indeed.
When viewing pages served by controllers I am getting random characters show up in the URL - but the site still works, I think.
For example, navigating to /Route/Index takes me to (S(1t2ba055d2unxyqllwuntf55))/Route/Index
Why are these odd characters being generated?
My routes look like this in Global.asax
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
routes.IgnoreRoute("{resource}.asmx/{*pathInfo}");
routes.IgnoreRoute("{resource}.svc/{*pathInfo}");
routes.MapRoute("Route", "{controller}/{action}/{id}",
new { action = "Index", id = "" });
I was informed I had to add a default route without a controller otherwise people could not navigate to / (the root). MVC would try and map this. Wonder if this controllerless rule is part of the issue.
Thanks
(1t2ba055d2unxyqllwuntf55) looks like cookie-less sessions. Check your web.config and make sure it reads something like:
<sessionState cookieless="false" />

Resources