get subdirectory relative URL from relative URL - asp.net-mvc-4

We have an MVC4 application,
there is a navigation panel at left side of the screen and this navigation tree is built dynamically along with additional parameters.
so we store the navigation Url in a column in a table (say /Dataset/Financial).
now when application is hosted on a subdirectory(say http://localhost/xyzabcd/) the Url generated dynamically from the table still targets the root(ie., http://localhost/Dataset/Financial).
I got to know that Url.Action() will actually solve the problem.
Now since it has been designed like that, I would like to know if there is any standard way I can get the fully qualified URL for a relative URL(so that we don't have to make any change in the db)? Is there any built-in or existing method for doing this?

If you add the scheme/protocol, it should give you the FQDN that you're looking for.
Example
Url.Action("Action", "Controller", new { routeData = 1}, "http")
Note, that routeData I just put in as a placeholder. You could set that to null if desired. Also, "http" could also be "https"

Related

Images are not displayed properly in .net 5

In one control I try to display images using JavaScript. Everything is fine as long as I am in the URL controller
https://localhost:44300/Campaigns
But when I refer to the index, the images are not displayed, even though I am on the same page or after the Redirect ("Index").
https://localhost:44300/Campaigns/index
The root address does not seem to be working properly
This is my image address when it works properly in Campaigns
https://localhost:44300/uploads/f09ef469-0893-4089-8491-78707d097b0e.jpg
This is my image address when it does not work properly in Campaigns/Index
https://localhost:44300/Campaigns/uploads/f09ef469-0893-4089-8491-78707d097b0e.jpg
The CSS and js address images in the layout work well, and I used UseStaticFiles() in the Configure.
It is because you are referring to the images with a URL that is relative to your current page. You need to use a URL that is relative to your site root. You can change this by prefixing the URL with / where you are constructing them.
Eg instead of something like
uploads/f09ef469-0893-4089-8491-78707d097b0e.jpg
Use
/uploads/f09ef469-0893-4089-8491-78707d097b0e.jpg

How can I add an application name at the start of a Razor Pages route?

Say I have a RazorPages application with pages in folders under the Pages folder like in the image below:
pretty standard. I want this application to be available for different clients so that they use different URLs to access it. I can use a #page "/RRate/Index/{sName}" directive in the RRate\Index.cshtml file so that the URL <root>\RRate\Index\client_namewill bind client_name to sName.
My question is: Can I use a URL like <root>\client_name\RRate\Index so that the client name is the first part of the route? How would I implement a route like that?
Not surprisingly, a #page "/{sName}/RRate/Index" directive does not work.
I am using .NET Core 3.1, services.AddRazorPages(); and endpoints.MapRazorPages(); in startup.
I have looked at endpoints.MapDynamicControllerRoute() but this approach does not seem to mesh with Razor pages. Am I wrong?
Well the answer was in the article mentioned by #mj1313.
I added PageRoutes for each page (I wander if there is a way to do this in one route) like the following: options.Conventions.AddPageRoute("/RRate/Index", "{survey}/RRate/Index");.

Customizing Route in Vue

I'm using Vue and I currently have a page setup that is in the folder structure:
/pages/tg/_tg_id.vue
The setup is working fine as going to website.com/tg/<user-id> resolves to the user's page based off ID.
I'm now being asked to include a username in the URL, but I still need the id as names change and some user's don't even have a name. As a solution I'd like the new URL structure to be:
website.com/tg/<user-id>/<any string>
So that we can use a link that has the username in it, purely for vanity purposes (putting any string after the last slash should resolve in the exact same way).
I'm unsure of how to set something like this up, currently my nuxt.config.js file has no routing settings. Is there something I can add to settings to get the desired behavior?
If you need only second option with username you can just rename your page to
/pages/tg/_tg_id/_username.vue
and thats it.
If you still need your first url too you can use https://github.com/nuxt-community/router-extras-module and define alias inside your page or by extending routes by hand.

Are links in Polaris embedded app supposed to not change url path?

I'm using Next.js with Polaris (from following their guide here). Using Link component imported from either Polaris or Next.js is not updating the url in the embedded app.
While the url path doesn't change, the view does change correctly (i.e. the component for the new path does render). Same result with breadcrumbs and url prop for ResourceList.
Is this expected behavior?
Ended up figuring this out after many variations of trying to make links work correctly.
Answer: no, that's not expected behavior and links should change url path for Shopify embedded apps.
For Polaris, in order to make links change the URL you will need to install this library (#shopify/react-shopify-app-route-propagator). There is enough instructions on the page to figure out how to install it.
Important note on library usage: AppProvider had to be in the parent component for this.context.polaris.appBridge to work correctly. All the logic for context needed to be in a child component. This issue might've been unique to just my case, but maybe not.

DNN get params in view are not available in edit

I am creating a dnn module. The content depends on the param in the url.
I want to be able to edit this content in the 'edit content' mode. However when i go to edit content the param in the url is no longer accessible because it is the parent document. How do i go about passing this value from the view.ascx to the edit.ascx?
Try storing the param in cookies or localstorage. Then you should be able to access it. Of course the user will be able to modify it but you can do a check that the user has not modified it by storing a server side encryption or somthing like that.
A workaround is to have a field where the user enters this parameter. But i know this isn't a very good solution. I am guessing that you will have to override the dotnetnuke core to do this (yes i know it sucks).
I hope I am understanding the question properly.
To pass parameters from your View to Edit controls, you should first make sure they are registered properly in the module definition. You default View should have an empty controlkey and your Edit should be registered with a control key, for example "addedit".
When creating a link between your view control and edit control, use the EditUrl() method of PortalModuleBase. When passing a parameter, for example an id of the item you want to load into your edit control, you can pass them as arguments in the EditUr method.
Example (in my view.ascx.cs):
lnkEdit.NavigateUrl = EditUrl("id", "16", "addedit");
This will assign a module view link to the edit.ascx (assuming the controlkey in the definition is addedit) passing in a url parameter "id" with value 16.
See my DNN Module Views tutorial for a complete lesson on how to do DNN module views and navigation.
http://www.dnnhero.com/Premium/Tutorial/tabid/259/ArticleID/204/Introduction-and-Module-Definition-basics-in-DNN-Part-1-6.aspx