- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想弄清楚如何枚举 Routes
的 URL。在 RouteTable
.
在我的场景中,我定义了以下路由:
routes.MapRoute
("PadCreateNote", "create", new { controller = "Pad", action = "CreateNote" });
routes.MapRoute
("PadDeleteNote", "delete", new { controller = "Pad", action = "DeleteNote" });
routes.MapRoute
("PadUserIndex", "{username}", new { controller = "Pad", action = "Index" });
PadController.CreateNote()
和 mysite.com/foobaris 调用
PadController.Index()
.
public class Username
{
public readonly string value;
public Username(string name)
{
if (String.IsNullOrWhiteSpace(name))
{
throw new ArgumentException
("Is null or contains only whitespace.", "name");
}
//... make sure 'name' isn't a route URL off root like 'create', 'delete'
this.value = name.Trim();
}
public override string ToString()
{
return this.value;
}
}
Username
的构造函数中,我想检查以确保
name
不是定义的路线。例如,如果这被称为:
var username = new Username("create");
//... make sure 'name' isn't a route URL off root
和?
最佳答案
这并不能通过阻止用户注册 protected 词来完全回答您想要做什么,但是有一种方法可以限制您的路线。我们的网站中有/username url,我们使用了这样的约束。
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" }, // Parameter defaults
new
{
controller = new FromValuesListConstraint(true, "Account", "Home", "SignIn"
//...etc
)
}
);
routes.MapRoute(
"UserNameRouting",
"{id}",
new { controller = "Profile", action = "Index", id = "" });
System.Web.Routing.RouteCollection routeCollection = System.Web.Routing.RouteTable.Routes;
var routes = from r in routeCollection
let t = (System.Web.Routing.Route)r
where t.Url.Equals(name, StringComparison.OrdinalIgnoreCase)
select t;
bool isProtected = routes.Count() > 0;
关于asp.net-mvc - 枚举 ASP.NET MVC RouteTable 路由 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4442766/
我有一个几个月前创建的 Web 窗体应用程序,并添加了一个 Web API Controller 。我尝试使用最近在演示文稿中看到的“自动”路由,但我得到的只是 404。然后我尝试使用 MapHttp
我想从 RouteTable 中检索路由值,但它为空。有人可以帮忙吗? public static class GetRouteValues { public static string Ge
我随处看到的 MVC 风格路由的示例是这样的: void Application_Start(object sender, EventArgs e) { RegisterRoutes(Rout
我得到了一个 ASP.NET MVC 2.0 Preview 1 应用程序,并开始创建一些包含自己的路由的区域。 我希望有一种方法可以在主项目中覆盖这些路由。我当然不能添加同名的新路线。我可以看到 R
如何通过key获取RouteTable.Routes集合中的url? 最佳答案 未经测试,但在这里看到 link RouteTable.Items[ "myRouteName" ] 要获取 Url,我
我在 AspNet MVC 4 应用程序中使用 SignalR 1.1.2 版本和温莎城堡。我的问题是,自从我移动到较新的 SignalR 版本后,此错误消息就出现了。 "The requested
这个问题在这里已经有了答案: How to get RouteData by URL? (2 个回答) 7年前关闭。 我的一个 Controller 的 Action 中有一个字符串,它表示一个引用
我们在我们的网站上有一个区域,人们可以在那里注册并在我们希望在 ~/pageSlug 上托管的网站上获得他们自己的页面。我已经尝试使用 Global.asax 中的规则来完成它,但这破坏了允许 ~/C
我想知道为什么路由似乎可以从 HttpConfiguration 对象和 RouteTable 类配置?很明显,这两个 .Routes 属性的类型不同,但它们似乎保持同步。他们有可能不同步吗?我想知道
在我的 Global.asax 我有这些规则 protected void Application_Start(object sender, EventArgs e) {
我正在尝试使用cloudformation创建vpc,并使用单个公共(public)子网、路由表和互联网网关。问题是即使我只包含 1 个路由表,也会创建与 vpc 关联的两个路由表。 下面是我的代码
我有一个分页 Controller ,其方法调用 RouteTable.Routes.GetVirtualPath(this.viewContext.RequestContext, valueDict
我想弄清楚如何枚举 Routes 的 URL。在 RouteTable . 在我的场景中,我定义了以下路由: routes.MapRoute ("PadCreateNote", "create",
我想枚举我的应用程序中的所有路由,并获取它们的 URL。我怎样才能做到这一点? 最佳答案 也许尝试这样的事情: List ApplicationRoutes = new List(); foreach
我在 MVC 3.0 Windows Azure 应用程序中使用 SignalR。以下行仅在 Windows Azure 模拟器中引发 ArgumentNullException。如果我运行 MVC
我正在尝试让 ASP.NET MVC Web API 在我的 Web 表单解决方案中工作。不,不幸的是我不能将所有内容都切换到 MVC。现在我被困在映射我的 HttpRoute 上。我目前正在尝试将路
我是一名优秀的程序员,十分优秀!