I am developing a CMS that stores user content in a database table like this:
----------------------------------------
PageId | PageTitle(Unique) | Content
----------------------------------------
1 | PageOne | ...
2 | PageTwo | ...
3 | PageThree | ...
4 | PageFour | ...
Now I have an aspx page "SitePageFactory.aspx" at root that serves dynamic content when a querystring is passed to it, suppose /SitePageFactory.aspx?pgid=1 is passed then it serves the content for PageOne.
The concept above is working fine.
Now I want to put a step further by adding dynamic routes to this application and modify /SitePageFactory.aspx?pgid=1 to /PageOne.aspx but unable to do it at root level.
NOTE: Currently I am able to perform routing like /SitePageFactory/PageOne.aspx but I want the results at the root level.
Thanks.
You can use ASP.NET Routing to accomplish this.
Routing let's you map an url like: www.mysite.com/pages/pageone to an aspx page. The different parts in your url can be mapped to route parameters that you can access in your aspx.
Here is the MSDN documentation for routing.
You can add the folowing route:
routes.MapRoute("ViewPage",
"<PageName>",
new { controller = "Page", action = "ViewPage" }
This will map the url www.yourdomain/ to the Page controllers ViewPage method.
Related
I have to implement 3 dynamic page routes in nextjs App.
/blog/category/postname
/blog/category
/blog/postname
I can implement 1 & 2 routes as dynamic routes but the problem is with the 3rd one. Actually, I need 3rd one because the production site is having the same slug for some of the posts. so want to maintain the same slugs in my nextjs application as well. Is there any solution to implement this??
You have an example here.
In your /pages:
You create blog folder.
Case 1 (excluding root): In blog, you create [...slug].js (or .tsx)
Example: /blog - ERROR ;/blog/category - OK; /category/postname - OK
Case 2 (lot of levels, including root): In blog, you create [[...slug]].js (or .tsx)
Example: /blog - OK;/blog/category - OK; /category/postname - OK
You handle all logic inside this file.
You can check my answer to understand how routing is done.
I have many levels of user permissions in my site.
So a junior user can NOT do things that a senior user can do. ( there are many levels of users. senior vs junior is just for simplification).
In addition to a server side validation for who is the user and what he can/t do — I also want NOT to provide the Javascript function registration at first place . (So if a user is a junior user , then his JS files should not contain JS functions of a senior user.)
Example :
The site has a general add javascript function which should appear to all users:
function add() {
console.log("Add");
}
Junior users has higher privilege so they can ALSO do subtract . so their JS files include the subtract method:
function substract() {
console.log("substract");
}
A general users won't have this substract method
Senior users has higher privilege so they can ALSO do power. so their JS files include the power method :
function power() {
console.log("power");
}
A senior user won't have this power method
OK
According to this answer :
Note that you must have a separate bundle per page. You should not
modify one and the same bundle on the fly....etc...
So , I created ( for now) 2 bundles , one for each page :
bundles.Add(new ScriptBundle("~page1Junior").Include(
"~/Scripts/General.js", "~/Scripts/Junior.js"));
bundles.Add(new ScriptBundle("~page1Senior").Include(
"~/Scripts/General.js", "~/Scripts/Senior.js"));
And then I take the relevant bundle according to some login and use :
<script src='#Scripts.Url("~/page1Senior (or) Junior")' async> </script>
Question
This seems like a wrong way to go.
If I have 10 pages and 10 user levels , According to that approach , I will need 100 different bundles.
what is the right way of serving appropriate js files for their relevant user permissions ?
Pseudo code of what i'm after :
user level js files(combined to one)
------------|-------------
1 [a,b]
2 [a,b,c]
3 [a,b,c,d]
4 [a,b,c,d,e]
So If a user level 3 is logged on , then a single abcd.js JS file should be served ( minified).
One way is to use DynamicBundleFolder
If you can have a directory structure like
Scrtips
-- /Permissions
-- /1
-- a.js
-- b.js
-- /2
-- a.js
-- b.js
-- c.js
-- /3
-- c.js
-- d.js
where 1,2,3 are the restriction levels, then in your RegisterBundles add a DynamicBundle
bundles.Add(new DynamicFolderBundle("userScripts", "*.js",new JsMinify()));
And then in your _layout.cshtml, you can do
#{
var userPermissionLevel = 2; // grab your user permission level, from session maybe
}
#Scripts.Render("~/Scripts/Permissions/"+ #userPermissionLevel +"/userScripts")
and that will render all the scripts in that directory. You dont have to create bundles for each page then. And if you need to add new permission based file, just add to respective permission folder.
Update: This will work fine if you have unique js files for each permission level. For shared files, updating them will be quite a work. So what you can do is create bundle according to permission levels like
// Bundle for permission level 1
bundles.Add(new ScriptBundle("~/bundles/permissions/1").Include(
"~/Scripts/a.js")
.Include("b.js"));
// Bundle for permission level 2
bundles.Add(new ScriptBundle("~/bundles/permissions/2").Include(
"~/Scripts/b.js")
.Include("c.js"));
// and so on for each level 3,4,5 include specific level files
and then again you can add them to page throught _layout.cshtml
#{
var userPermissionLevel = 2; // grab your user permission level, from session maybe
}
#Scripts.Render("~/bundles/permissions/"+userPermissionLevel)
I am quite new to writing Behat test suites and I am currently trying to flesh out my existing feature file with an added test to test an uploaded file.
This is what I have come up with so far.
Scenario: Submitting a valid asset form and uploading a file
When I submit a asset form with values:
| name | type | position | active | file |
| St Andrews Release | image | 1 | 1 | /web/images/product/icon/default.jpg |
Then the form should be valid
And the entity form entity should have the following values
| name | type | position | active | file |
| St Andrews Release | image | 1 | 1 | /web/images/product/icon/default.jpg |
Failed asserting that null matches expected '/web/images/product/icon/default.jpg'.
And the entity form entity should be persisted correctly
This is the method handling the scenario:
/**
* #When I submit a asset form with values:
*/
public function iSubmitAssetFormWithValues(TableNode $table)
{
$data = $table->getColumnsHash()[0];
$this->form = $this->submitTheForm('crmpicco.asset.type', $this->entity, $data);
}
The submitTheForm method returns a Symfony\Component\Form\FormInterface.
Am I along the right lines? I am currently getting an error:
Failed asserting that null matches expected
'/web/images/product/swatch/default.jpg'.
I suggest you to create a dedicated folder structure for files which will be used in behat tests right in your application root because tests and the files used in tests must be consistent for all developers. I sometimes see people writing tests to upload files that exist on their local desktop:) My desktop and your desktop would be different hence reason the test would fail.
Structure
football #your application name/root
build
dummy
document
hello.doc
world.xls
image
test.jpg
behat.yml
Apart from other common setting, you must define file_path.
....
....
default:
extensions:
Behat\MinkExtension\Extension:
files_path: %behat.paths.base%/build/dummy/
....
....
Example Gherkin scenario
Feature: I can upload a file which is stored in my generic "dummy" folder
Scenario: I can upload image
Given I am on "/"
When I attach the file "image/test.jpg" to "league_flag"
And I press "Submit"
Then I should see "Succeeded."
OK, just as the title asked, I currently worked on a asp.net website, I found out that all the aspx and ascx files actually stay in one namespace, however there are different directory hierarchy between them. See below example.
Mainsite
| Dialogs
| | Help.ascx
| | Price.aspx
| Includes
| | QuickLink.acsx
| Members
| Orders
| Login.aspx
| Default.aspx
Like above example, all aspx ans ascx files belong to namespace Order, however Login.aspx and Price.aspx are in different directory. I mean by default when you create a aspx file in certain directory, the default namespace will inherit the directory information.
The thing is that I found at a frequently happened bug, is in Default.aspx there is ajax call to Dialogs/Price.aspx, then the error message can not find Dialogs/Dialogs/Price.aspx, it is weird.
I'm thinking of learning the ASP.NET MVC framework for an upcoming project. Can I use the advanced routing to create long URLs based on the sitemap hierarchy?
Example navigation path:
Home > Shop > Products > Household > Kitchen > Cookware > Cooksets > Nonstick
Typical (I think) MVC URL:
http://example.com/products/category/NonstickCooksets
Desired URL:
http://example.com/shop/products/household/kitchen/cookware/cooksets/nonstick
Can I do this?
Zack, if I understand right you want unlimited depth of the subcategories. No biggie, since MVC Preview 3 (I think 3 or 4) this has been solved.
Just define a route like
"{controller}/{action}/{*categoryPath}"
for an url such as :
http://example.com/shop/products/household/kitchen/cookware/cooksets/nonstick
you should have a ShopController with a Products action :
public class ShopController : Controller
{
...
public ActionResult Products(string categoryPath)
{
// the categoryPath value would be
// "household/kitchen/cookware/cooksets/nonstick". Process it (for ex. split it)
// and then decide what you do..
return View();
}
The MVC routing lets you define pretty much any structure you want, you just need to define what each of the pieces mean semantically. You can have bits that are "hard-coded", like "shop/products", and then define the rest as variable, "{category}/{subcategory}/{speciality}", etc.
You can also define several routes that all map to the same end point if you like. Basically, when a URL comes into your MVC app, it goes through the routing table until it finds a pattern that matches, fills in the variables and passes the request off to the appropriate controller for processing.
While the default route is a simple Controller, Action, Id kind of setup, that's certainly not the extent of what you can do.