ASP.NET URL Routing help needed in asp.net 4.0 application - url-routing

I am going to implement routing feature in my asp.net4.0 application and following the given link:
URL-Routing
This is fine if an application has limited no. of pages but my application has lots of pages.
so i have to write code [ routes.MapPageRoute("","",""); ] many times.
Can we map all pages by looping through any collection classes or by any other method.
Thanks

If you have a standard pattern for your url and your file structure you can use the placeholders in the mapped url too
eg. If you can map every "{controller}/{action}/{id}" to "/Pages/{controler}/{action}.aspx"
For example, i build a site that has this folder structure
Under the root folder there is the Views folder where all my pages reside.
Under the Views folder there is one subfolder for every "controller" (there is no controllers in webforms, but I follow the MVC conventions here)
Under the controllers subfolders there are the aspx pages that represent different actions
The aspx page names are the same for each controller ("Index.aspx","Add.aspx","Edit.aspx" etc)
So I can have a general mapping rule
routes.MapPageRoute("GeneralAction", "{controler}/{action}/{id}", "~/Views/{controler}/{action}.aspx");
I don't need different rules for different pages as long as the folder structure follows this pattern
Now
"/Patient/Add" will map to "~/Views/Patient/Add.aspx"
"/Incident/Add" will map to "~/Views/Incident/Add.aspx"
"/Patient/Edit/31" will map to "~/Views/Patient/Edit.aspx" (with id=31)
etc, all matching this one rule above.
of course if you want to override this rule you can define more specific routes BEFORE defining this one.

Related

What is the optimal architecture combining Scala-Play and AngularJS?

I have recently worked in a pure Scala-Play application and later in a pure AngularJS application. I'm very impressed with both and I'm wondering what is the sweet spot of combining the two frameworks together. Since the two frameworks can be complementary but also overlapping in different areas e.g. MVC and page routing, as far as I know these are some of the possibilities:
Single Page design, use AngularJS MVC-only and use Scala-Play as "dull" service layer backend with no full page refreshes.
Allow page reloads and each page reload becomes a different AngularJS root application. This seems quite flexible e.g. the client side is not bloatted with so much data for larger applications but better partitioned for the different use-cases. The downside is that I'd need different AngularJS MVC applications and I'm not even sure how to organize it as a project. Are there examples of this?
Typical server side Web App, use Play MVC-only and AngularJS for handling UI models for each separate page.
My choice of IDE for these types of architecture would of course be WebStorm but unfortunately I can't have all client-side (AngularJS and JavaScripts) and sever-side (Scala-Play) codes in a single project.
I believe that there is no the ultimate optimal architecture for combining Play and Angular. It depends on the specificity of the project, team etc.
The decision to develop UI part with Angular and the server side back-end with Play is very reasonable. Technically it may be done as following:
Development:
Both parts are developed as detached projects with the preferable IDE.
The client should have some entry point HTML page. It is reasonable to name it index.html, but is may be any other name.
For client-server integration do on the Play side as following:
Select a sub-folder under the play application root, which will serve as the "home" for the client files. The default solution is to use the folder public, since all files under it are automatically deployed.
All client files should be copied under the public folder. The files may be organized in any structure.
Add a route for the default URL as a route to the index.html. The argument path in the route should be the full path of the index.html relatively to the application root.
If index.html is directly in the public folder, the route is like this:
GET /defaultUrl controllers.Assets.at(path="/public", file ="index.html")
Add routing to the client files:
GET /*file controllers.Assets.at(path="/public", file)
Now the distribution package will include all the client files.
Putting of the client files into the public folder should be done automatically, for example by organizing the client directory structure and appropriate configuration of the client IDE.
You can find more examples in this post.

What should be the Best directory structure/architecture for angularjs in your project [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
i am developing a new massive project in larvel5 and angularjs , i just needed suggestions for what should be the best directory structure for angularjs to organize your code in inside my projects.how should be modules, controllers, directive and factory etc managed inside my project. my default directory structure is like
app
controllers
services
directives
In this, There are two web projects, one is or web api and another one is for client web page (SPA).
You just need a empty web project to start an angular project.
Index.html - It is the main html page for your application. All other pages (partial pages) for your project can be placed Inside the directory Pages.
Scripts - All your js files can be placed inside this directory. You can differentiate all your js files into it's sub-directories.
An ideal AngularJS app structure should be modularized into very specific functions. We also want to take advantage of the wonderful AngularJS directives to further compartmentalize our apps. Take a look at a sample directory structure below:
index.html
The index.html lives at the root of front-end structure. The index.html file will primarily handle loading in all the libraries and Angular elements.
Assets Folder
The assets folder is also pretty standard. It will contain all the assets needed for your app that are not related your AngularJS code. There are many great ways to organize this directory but they are out of scope for this article. The example above is good enough for most apps.
App Folder
This is where the meat of your AngularJS app will live. We have two subfolders in here and a couple JavaScript files at the root of the folder. The app.module.js file will handle the setup of your app, load in AngularJS dependencies and so on. The app.route.js file will handle all the routes and the route configuration. After that we have two subfolders – components and shared. Let’s dive into those next.
Components Folder
The components folder will contain the actual sections for your Angular app. These will be the static views ,directives and services for that specific section of the site (think an admin users section, gallery creation section, etc). Each page should have it’s own subfolder with it’s own controller, services, and HTML files.
Each component here will resemble a mini-MVC application by having a view, controller and potentially services file(s). If the component has multiple related views, it may be a good idea to further separate these files into ‘views’, ‘controllers’, ‘services’ subfolders.
This can be seen as the simpler folder structure shown earlier in this article, just broken down into sections. So you could essentially think of this as multiple mini Angular applications inside of your giant Angular application.
Shared Folder
The shared folder will contain the individual features that your app will have. These features will ideally be directives that you will want to reuse on multiple pages.
Features such as article posts, user comments, sliders, and others should be crafted as AngularJS Directives. Each component here should have it’s own subfolder that contains the directive JavaScript file and the template HTML file.
In some instances, a directive may have it’s own services JavaScript file, and in the case that it does it should also go into this subfolder.
This allows us to have definitive components for our site so that a slider will be a slider across the site. You would probably want to build it so that you could pass in options to extend it.
You can read detailed article from here
You can also take a look at these links :
Angularjs style guideline and
another article
found a solution for my angularjs directory structure.

Change Angularjs existing backend to Play 2

I have a fully developed Angularjs frontend app (with the routes and everything set up) and would like to change the current backend to a Play 2 Java. What is the best approach to display the existing html files from Angular in Play? I have found a few examples of how to connect the routes, but I would rater not create an index.scala.html file as I would like to have the two frameworks separated as much as possible and having Play only working as backend.
If you don't want to dynamically generate views from Play using Twirl and you just want to serve your HTML static files publishing them as assets is the way to go. By default assets are designed to provide resource like CSS or JS files but nothing prevents you from serving ordinary HTML views as well.
Simply put your index.html in the public directory and modify the conf/routes files so it can handle all requests:
GET /*file controllers.Assets.at(path="/public", file)
This way your index.html will be accessible at www.yourdomain.com/index.html. Remember to put this line as the last mapping in the file as it matches all possible URLs. Other services should be declared above it.

Best File Structure with ASP.NET Web Api

I will begin web project with AngularJS and want to organize my files appropriately including Web Api.
What is the best structure to use?
The detailed explanation of file structure in AngularJS is explained in AngularJS Up & Running by Shyam Seshadri & Brad Green.
Here is few tips from the book.
Have one controller, service, directive, or filter per file. Don’t club them into large
single files.
Don’t have one giant module. Break up your applications into smaller modules. Let
your main application be composed of multiple smaller, reusable modules.
Prefer to create modules and directories by functionality (authorization, adminservices,
search, etc.), over type (controllers, services, directives). This makes your
code more reusable.
Groups by functionality (login, autohorization)
Creates folder to reusable components (datepicker, widgets)
Creates seperate folder to third-party dependencies.

cakephp for multiple static sites

I have successfully created a static website using cakephp to create the static html files using the console.
However, what I want to do now is have a console script that can create multiple websites from the same shared data, with each website using data that is unique to it, but sharing the db as a source.
So, how do I set up the app folder in relation to each website? Do I need a separate installation of cakephp for each site? Or can I have a shared App folder in cgi-bin or something like that?
Thanks
You can share the CakePHP core between multiple apps, however you will need a separate 'app' folder for each website (with the appropriate structure). See this question for more details. Essentially you will need to modify the index.php file in each app/webroot folder to point to the CakePHP core. I use this technique and it's much easier to maintain with only one core as opposed to a whole separate installation of Cake for each site.

Resources