Hi I am working on a SPA application using the Hot Towel template and asp.net MVC.My applications home page is curently set to point to the Home and Index controller in RouteConfig.cs.
I have to change that route to point to a Durandel view.
This link should be the one that opens my homepage:
http://localhost:61620/Home/MyCourses#/dashboard
If it was asp.net mvc I would set it in RouteConfig.cs.If that is still the case how can I do that?If not where should I set this?
Typically, in a Durandal-based SPA, there is code in the shell's activate function that uses the router to activate the "home" page. In a Hot Towel template, this code is in the shell's boot() function. This code normally looks like this:
function activate() {
return boot();
}
function boot() {
... //router setup
return router.activate('home');
}
This sets up the app so that, when the user browses to http://localhost:61620/Home/MyCourses#/, the app will load the dashboard route automatically, even though it may not be part of the literal url.
Related
I am building a custom angular app in Grails, but sticking as much as possible to the default Grails Controller View behaviour.
What I'm trying to do is: using the scaffolding controller. Get the same behaviour but by ading a #/ to the start of the url. So that after you save a Record, you'd be redirected to:
http://localhost:8080/#/country/show/5
instead of
http://localhost:8080/country/show/5
So that Angular kicks in again. I know this isn't the standard Angular behaviour but I'm trying to use as few angular files as possible since I have very little knowledge in angular.
The default scaffolding redirect is:
redirect country
And I tried using:
redirect base: "#/", country
redirect country, [base: "#/"]
redirect country, base: "#/"
redirect absolute: "#/", country
But they all throw 500 error when called.
This is my current app config in angular:
app.config(function($routeProvider) {
$routeProvider.when("/:controller/:action",{
templateUrl:function(params){
return '/'+params.controller+'/'+params.action;
}
})
.when("/:controller/:action/:param",{
templateUrl:function(params){
return '/'+params.controller+'/'+params.action+'/'+params.param;
}
});
});
Have you tried this?
class SomeController {
LinkGenerator linkGenerator
def action() {
redirect uri: linkGenerator.link(
controller: 'country', action: 'show', id: 5, base: '/#')
}
}
UPDATE: Given the requirement to support multiple formats, teaching angular to work with "pretty" URLs might be the only way. Here is an example posting that has the following code:
angular.module('scotchy', [])
.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl : 'partials/home.html',
controller : mainController
})
.when('/about', {
templateUrl : 'partials/about.html',
controller : mainController
})
.when('/contact', {
templateUrl : 'partials/contact.html',
controller : mainController
});
// use the HTML5 History API
$locationProvider.html5Mode(true);
});
I ended up giving up on angular entirely. To show the views inside a dialog I just extract the html segment from the response returned from the server and I get all the default behaviour that Grails includes out of the box.
Since grails is a full stack framework and it's front end is highly customizable. Unless you want to build an entire angular app it's not worth replacing the front end with angular just for it's single view capabilities.
The server responses may be slightly bigger than what I need to show inside a dialog, but it doesn't hurt performance. And the controllers don't know if their views are being rendered inside a dialog or as a full web page, which is what I wanted in the first place.
I have a rails app with dashboard page. So the page will be http://mywebsite.com/dashboard. It has few links available which will load pages via ajax and show it in a div section inside the dashboard page. Its all working fine. So lets assume I want to use angular here and I specify code like below.
var myapp = angular.module('myapp', ["ui.router"])
myapp.config(function($stateProvider, $urlRouterProvider){
$stateProvider
.state('route1', {
url: "/route1",
templateUrl: "route1.html"
})
})
My doubt is that:
So in here if dashboard is the root url then the url generated is http://mywebsite.com/#route1
What if my dashboard page is defined like this
http://mywebsite.com/dashboard and I want to define route like http://mywebsite.com/dashboard/#route1
Note: Its not a single page application. But I want the dashboard page
to be like a single page one..
This will work fine and the route will be relative to your URL
http://mywebsite.com/dashboard.
If you were using HTML5 mode with Angular UI router if you try and interoperate the full URL. But because you are not using HTML5 mode, Angular UI router routes using #.
I have an older web-form app and now I am trying to add new pages using MVC.
It all seems to work just fine except one thing:
The application's default page (login.aspx) is a web form.
When user hit link www.mysite.com, instead of opening www.mysite.com/login.aspx, the site immediately goes to route specified in global.aspx as
routes.MapRoute("FrontLine", "{controller}/{action}/{id}",
new { controller = "FrontLine", action = "QuickView", id = "" });
So, the question is how to make login.aspx a default page?
Is it possible to do without converting login.aspx to a MVC view and adding corresponding controller?
Found a solution:
excute line:
routes.MapPageRoute("Default", "","~/Login.aspx")
before calling
routes.MapRoute
I am working on a Grails app that has two websites: a regular "desktop" site, and a mobile site where all the presentation is done using jQuery Mobile. To distinguish these sites, I use the default Grails controllers for the regular site, and I have a custom "mobile" controller for all the mobile pages and actions. The Grails Spring Security plugin is used to handle all the authentication & authorization stuff.
So far so good. But here's my issue. On the restricted pages/actions the security plugin automagically intercepts the call (when the user is not properly authenticated) and redirects to the login page. However, I want to use 2 different pages: 1 for the regular site, and one for the mobile site. I can't figure out a good way to determine in which "context" the user is ("context" being regular or mobile).
My quick & dirty solution sofar: if a user goes to a mobile non-restricted page first, I put a marker "mobile session" in the session object. In the login controller I look for that marker and set the view to the mobile login page. Like so:
def auth = {
def config = SpringSecurityUtils.securityConfig
if (springSecurityService.isLoggedIn()) {
redirect uri: config.successHandler.defaultTargetUrl
return
}
String view = 'auth'
if (session.mob) {
log.debug "we're in a mobile session; reset view"
view = 'mauth'
}
String postUrl = "${request.contextPath}${config.apf.filterProcessesUrl}"
render view: view, model: [postUrl: postUrl,
rememberMeParameter: config.rememberMe.parameter]
}
This doesn't work of course, if the first page the user navigates to is a restricted page.
I hope someone can help me with this one. One "restriction" on the solution: I don't think it's a good idea to examine the user-agent to determine the context (the regular site will/must work an any device); I would prefer to determine the context based on the request being an action of the mobile controller.
When spring security redirects you to the auth action, it stuffs the original URI into the session. If you can determine if a page is mobile from the URI, then you can select the view based on this. It will be available at session.SPRING_SECURITY_SAVED_REQUEST_KEY.requestURI.
How do you start debugging the application at the application root? For example: http://localhost:49742/
I'm always getting a page which doesn't exist, such as:
http://localhost:49742/Views/Home/About.aspx
Note that it would be OK to start at http://localhost:49742/Views/Home/About
Go to your project's properties and set the start page property.
Go to the project's Properties
Go to the Web tab
Select the Specific Page radio button
Type in the desired url in the Specific Page text box
While you can have a default page in the MVC project, the more conventional implementation for a default view would be to use a default controller, implememented in the global.asax, through the 'RegisterRoutes(...)' method. For instance if you wanted your Public\Home controller to be your default route/view, the code would be:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Public", action = "Home", id = UrlParameter.Optional } // Parameter defaults
);
}
For this to be functional, you are required to have have a set Start Page in the project.
This works for me under Specific Page for MVC:
/Home/Index
Update: Currently, I just use a forward slash in the "Specific Page" textbox, and it takes me to the home page as defined in the routing:
/
Selecting a specific page from Project properties does not solve my problem.
In MVC 4 open App_Start/RouteConfig.cs
For example, if you want to change startup page to Login:
routes.MapRoute(
"Default", // Route name
"", // URL with parameters
new { controller = "Account", action = "Login"} // Parameter defaults
);
If you want to start at the "application root" as you describe right click on the top level Default.aspx page and choose set as start page. Hit F5 and you're done.
If you want to start at a different controller action see Mark's answer.
Revisiting this page and I have more information to share with others.
Debugging environment (using Visual Studio)
1a) Stephen Walter's link to set the startup page on MVC using the project properties is only applicable when you are debugging your MVC application.
1b) Right mouse click on the .aspx page in Solution Explorer and select the "Set As Start Page" behaves the same.
Note: in both the above cases, the startup page setting is only recognised by your Visual Studio Development Server. It is not recognised by your deployed server.
Deployed environment
2a) To set the startup page, assuming that you have not change any of the default routings, change the content of /Views/Home/Index.aspx to do a "Server.Transfer" or a "Response.Redirect" to your desired page.
2b) Change your default routing in your global.asax.cs to your desired page.
Are there any other options that the readers are aware of? Which of the above (including your own option) would be your preferred solution (and please share with us why)?