asp.net-mvc 在 ASP.NET MVC URL 路由中包含哈希值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5567721/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Including hash values in ASP.NET MVC URL routes
提问by facebook
I need to implement hash value i.e the Url should look like this:
我需要实现哈希值,即 Url 应如下所示:
/home/index/#create
/家/索引/#创建
For this have added a route:
为此添加了一条路线:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/#{detail}", // URL with parameters
new { controller = "Login", action = "LogIn", detail =""} // Parameter defaults
);
On accessing /home/index/#create
, it is redirecting me to the default route.
在访问时/home/index/#create
,它将我重定向到默认路由。
How can this be done?
如何才能做到这一点?
采纳答案by Darin Dimitrov
You cannot fetch the value after the #
symbol on the server simply because this value is never sent to the server. Only client side javascript has access to this so defining routes with hash doesn't make much sense.
您无法#
在服务器上获取符号后的值,因为该值从未发送到服务器。只有客户端 javascript 可以访问它,因此使用哈希定义路由没有多大意义。
回答by Rory McCrossan
As stated there is no way to do this using routing. The only possible solution is to append the # fragment to your url when redirecting in the actions of your controller. Eg.
如前所述,使用路由无法做到这一点。唯一可能的解决方案是在控制器的操作中重定向时将 # 片段附加到您的 url。例如。
return Redirect(Url.Action("Index", "Home") + "#create");
回答by Robert Levy
When a browser makes a request for a URL, it does not send anything after a hash to the server. This route may enable you to generateroute URLs containing the hash value but there is no way to do anything server-sidewhen the user navigates to such a URL. That's just the way the web works...
当浏览器请求 URL 时,它不会在散列后向服务器发送任何内容。此路由可能使您能够生成包含哈希值的路由 URL,但当用户导航到此类 URL 时,无法在服务器端执行任何操作。这就是网络的运作方式......
回答by Joel Wiklund
OAuth 2.0 Implicit Flow
OAuth 2.0 隐式流程
If this has to do with OAuth 2.0 Implicit Flow
, you should use Authorization Code Grant
instead.
如果这与 有关OAuth 2.0 Implicit Flow
,则应Authorization Code Grant
改用。