urlhelper

ASP.NET Core UrlHelper and how it works

我的未来我决定 提交于 2021-01-21 06:57:45
问题 I'm rather new to ASP.NET Core, and right now I am trying to get a grasp on how UrlHelper works in general. In my controller, I want to create an absolute URL to another action in the same controller, e.g. http://localhost:PORT/api/controller/action . The question is now, how do I do it? I have tried with the following: var urlHelper = new UrlHelper(new ActionContext()); var url = urlHelper.Action("ACTION", "CONTROLLER"); Furthermore, what are those different contexts like ActionContext ? 回答1

How to add the slug to all Link generation in an asp.net core website?

时间秒杀一切 提交于 2020-12-02 08:03:18
问题 I need to be able to control the links being generated by my Url.Content("~") call to be able to accept a Slug in the beginning of the link. Basically the hosting URL will be behind a Load-balancer and may be at the root level or behind a friendlier Url... As an example: The site is configured to run under http://localhost:5001, so Url.Content("~/scripts/site.js") will generate "/scripts/site.js" this is fine if the browser is coming directly to that url or even to an alias such as www.mysite

How to add the slug to all Link generation in an asp.net core website?

安稳与你 提交于 2020-12-02 08:01:21
问题 I need to be able to control the links being generated by my Url.Content("~") call to be able to accept a Slug in the beginning of the link. Basically the hosting URL will be behind a Load-balancer and may be at the root level or behind a friendlier Url... As an example: The site is configured to run under http://localhost:5001, so Url.Content("~/scripts/site.js") will generate "/scripts/site.js" this is fine if the browser is coming directly to that url or even to an alias such as www.mysite

How to add the slug to all Link generation in an asp.net core website?

|▌冷眼眸甩不掉的悲伤 提交于 2020-12-02 07:59:46
问题 I need to be able to control the links being generated by my Url.Content("~") call to be able to accept a Slug in the beginning of the link. Basically the hosting URL will be behind a Load-balancer and may be at the root level or behind a friendlier Url... As an example: The site is configured to run under http://localhost:5001, so Url.Content("~/scripts/site.js") will generate "/scripts/site.js" this is fine if the browser is coming directly to that url or even to an alias such as www.mysite

ASP.NET Mvc 4 Use bundle's benefits for Url.Content

和自甴很熟 提交于 2019-12-24 03:36:05
问题 Is there any way I can do this? Some of the benefits of bundling are: Minimization Gzip compression The request has a token parameter for handling files versiones (cache). In my site I use a lot of bundles, but in some pages I only have 1 script and I don't think I should create a bundle only for 1 script. Is there any way I can use this three benefits with Url.Content method. My utopic solution would be to set up something (maybe in the web.config) and whenever Url.Content is called it adds

Rspec undefined local variable or method root_path

∥☆過路亽.° 提交于 2019-12-24 00:45:23
问题 I'm starting to use Rspec, but when I run bundle exec rspec I get an error /spec/requests/pages_spec.rb:20:in `block (2 levels) in <top (required)>': undefined local variable or method `root_path' for #<Class:0x00000102e46850> (NameError) I do not have Spork or Guard running so the question below shouldn't apply undefined local variable or method `root_path' (Rspec Spork Guard) I have added config.include Rails.application.routes.url_helpers in my spec_helper.rb file, but that did not help.

MVC UrlHelper called from Service

两盒软妹~` 提交于 2019-12-23 03:25:15
问题 I have a static class that sends emails with links to certain pages of my site. That link is getting dynamically generated with this code: UrlHelper urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext); string url = urlHelper.Action("Details", "Product", new { id = ticketId }, "http"); The problem is I now also have a service that periodically compares the creation date with the current date and sends those mails automatically. The code crashes of course and says HttpContext

Extending Zend\View\Helper\Url in Zend Framework 2

不打扰是莪最后的温柔 提交于 2019-12-22 10:57:36
问题 I wrote a simple url view helper, that extends Zend\View\Helper\Url and attached it to the ViewHelperManager : MyNamespace\View\Helper\Url namespace MyNamespace\View\Helper; use Zend\View\Helper\Url as ZendUrl; class Url extends ZendUrl { public function __invoke($name = null, array $params = array(), $options = array(), $reuseMatchedParams = false) { $link = parent::__invoke($name, $params, $options, $reuseMatchedParams); ... return $link; } } Application\Module namespace Application; use ..

MVC 6 IUrlHelper Dependency Injection

好久不见. 提交于 2019-12-22 03:24:56
问题 I want to use IUrlHelper through dependency injection to be able to use its functionality to generate uris for different rest endpoints. I cant seem how to figure out how to create a UrlHelper from scratch because it changed in MVC 6 and MVC doesnt automatically have that service available in the IoC controller. The setup is my Controller take in an internal model to api model converter class and that uses the IUrlHelper (all through Depenedency Injection). If there is a better alternative to

Use Separate js File And use Url Helpers in it with ASP.NEt MVC 3 and Razor View Engine

空扰寡人 提交于 2019-12-18 02:15:30
问题 I ask a similar question here and Darin Dimitrov answer that we can't use Url helper like $.ajax({ url: '@Url.Action("Index")', . . . in separate js file so what is your suggestion to use Url helper in view page and pass it to javascript, I don't want to use hard code url, I need to find it with Url helper.? 回答1: Use a hidden field to store your url, then use javascript to read the hidden field, then use that in your code. That way you can keep the JS file separate to the view. Something like