Tag: url routing

在Web浏览器中禁止保存/对话框并自动下载

我想通过客户端的链接自动下载exe提示。 我可以从http://go.microsoft.com/fwlink/?LinkID=149156获取第一个重定向链接到http://www.microsoft.com/getsilverlight/handlers/getsilverlight.ashx 。 请单击并检查其工作原理。 fwlink – > .ashx – > .exe …我想获得.exe的直接链接。 但是当通过代码请求Web处理程序时,响应返回404,但如果您尝试使用浏览器,它实际上会下载。 任何人都可以建议如何自动下载上述链接? 我用来获取重定向链接的代码就是这个。 public static string GetLink(string url) { HttpWebRequest httpWebRequest = WebRequest.Create(url) as HttpWebRequest; httpWebRequest.Method = “HEAD”; httpWebRequest.AllowAutoRedirect = false; // httpWebRequest.ContentType = “application/octet-stream”; //httpWebRequest.Headers.Add(“content-disposition”, “attachment; filename=Silverlight.exe”); HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse; if (httpWebResponse.StatusCode == HttpStatusCode.Redirect) { return httpWebResponse.GetResponseHeader(“Location”); } else […]

MVC3和重写

我正在编写一个MVC3应用程序,需要以http:// [server] / [City] – [State] / [some term] /的forms使用URL重写。 据我了解,MVC3包含一个使用{controler} / {action} / {id}的路由引擎,该引擎在Global.asax文件中定义: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”); routes.MapRoute( “Default”, // Route name “{controller}/{action}/{id}”, // URL with parameters new { controller = “Home”, action = “Index”, id = UrlParameter.Optional } // Parameter defaults ); } 传统上(在非MVC应用程序中),我会使用一些URL重写风格来解码诸如http://www.myserver.com/City-State/somesearch/之类的URL来查询类似于以下内容的查询字符串: http: //www.myserver.com/city=City&state=State&query=somesearch 请记住,此请求将来自http://www.myserver.com/Home 这可以在不必指定控制器的情况下完成……类似这样的事情: routes.MapRoute( […]

在不使用MVC更改URL的情况下为特定URL创建路由

我有一个在www.domain.com上运行的MVC Web应用程序,我需要为另一个域www.domain2.com为同一个Web应用程序配置不同的URL绑定。 新域名www.domain2.com必须返回特定的控制器操作视图,例如/Category/Cars : routes.MapRoute( name: “www.domain2.com”, url: “www.domain2.com”, defaults: new { controller = “Category”, action = “Cars”, id = UrlParameter.Optional } ); 如何在不更改URL的情况下实现此目的,以便访问者插入urlwww.domain2.com并收到视图www.domain.com/category/cars但url仍为www.domain2.com ? 编辑: 我尝试过这种方法,但它不起作用: routes.MapRoute( “Catchdomain2”, “{www.domain2.com}”, new { controller = “Category”, action = “Cars” } );

带有一个必需参数和一个可选参数的ASP.NET MVC路由?

在过去一个月左右的时间里,我一直在研究一个大型MVC应用程序,但这是我第一次需要定义一个自定义路由处理程序,而且我遇到了一些问题。 基本上我有两个参数要通过。 第一个是必需的,第二个是可选的。 我在这里听到这个答案。 这是我的自定义路线: routes.MapRoute( “MyRoute”, “{controller}/{action}/{param1}/{param2}”, new { controller = “MyController”, action = “MyAction”, param1 = “”, param2 = “” // I have also tried “UrlParameter.Optional” here. } ); 我的动作方法签名: public ActionResult MyAction(string param1, string param2) 如果我尝试URL http://[myserver]/MyController/MyAction/Test1/Test2那么它就像我期望的那样工作,param1 =“Test1”和param2 =“Test2” 如果我尝试URL http://[myserver]/MyController/MyAction/Test1那么两个参数都为null。 希望有人可以告诉我这里我做错了什么,因为我迷路了。

ASP MVC重定向而不更改URL(路由)

目标:我希望能够输入url:www.mysite.com/NewYork或www.mysite.com/name-of-business 取决于我想要在不更改URL的情况下路由到不同操作的字符串。 到目前为止我有: public static void RegisterRoutes(RouteCollection routes) { routes.MapRoute( “UrlRouter”, // Route name “{query}”, // URL with parameters new { controller = “Routing”, action = “TestRouting” } // Parameter defaults ); } 在控制器中我有: public ActionResult TestRouting(string query) { if (query == “NewYork”) return RedirectToAction(“Index”, “Availability”); // <——— not sure else if (query == "name-of-business") […]

跨多个子域的URL路由

我发现自己处境艰难。 我们正在开发一个ASP.NET MVC 2应用程序,它由多个部分组成。 设计目标是让这些部分跨越多个子域。 每个子域都有自己的控制器。 挑战在于我们的托管服务提供商的控制面板允许对子域进行两种forms的重定向,而且这两种forms都不符合要求。 选择是: 重定向到URL。 选择是否重定向到相对于请求URL的确切目的地或目的地。 重定向到我的主机空间中的特定文件夹。 我将尝试说明预期的行为。 假设默认路由是{controller}/{action}/{id} ,我希望URL http://subdomain.welcome.com/a/b由MVC应用程序处理,如http://welcome.com/subdomain/a/b 。 URL重定向可以解决此问题,除了用户在浏览器中看到URL更改的事实。 我们不希望客户端看到重定向发生。 重定向到我们的MVC应用程序根文件夹根本不起作用。 该应用程序不会接收请求,IIS会传回4xx错误。 编辑: 为了找到答案,我会简化一下。 “重定向到URL”不能执行我想要的操作,因此会重定向到文件夹。 如果我将子域重定向到我的MVC应用程序的根文件夹并且IIS不会接收请求,这是IIS或我的提供商的限制吗?

使用Web窗体进行ASP.NET路由

我读过ASP.NET Routing … Goodbye URL重写? 和使用路由使用WebForms是很棒的文章,但仅限于简单的,说明性的,“hello world” – 复杂的例子。 是否有人以非平凡的方式使用ASP.NET路由与Web表单? 有什么需要注意的吗? 性能问题? 进一步推荐阅读我应该先看看我自己的实现? 编辑找到这些额外有用的URL: 如何:使用Web窗体路由(MSDN) ASP.NET路由(MSDN) 如何:从路由构建URL(MSDN)

测试请求的URL是否在Route表中

我想测试一个URL是否是Global.asax定义的路由的一部分。 这就是我所拥有的: var TheRequest = HttpContext.Current.Request.Url.AbsolutePath.ToString(); var TheRoutes = System.Web.Routing.RouteTable.Routes; foreach (var TheRoute in TheRoutes) { if (TheRequest == TheRoute.Url) //problem here { RequestIsInRoutes = true; } } 问题是我无法从路由中提取URL。 我需要改变什么?

如何忽略asp.net中的路由表单url路由

我正在使用.NET 3.5 SP1框架,并在我的应用程序中实现了URL路由。 我收到了javascript错误: Error: ASP.NET Ajax client-side framework failed to load. Resource interpreted as script but transferred with MIME type text/html. ReferenceError: Can’t find variable: Sys 我相信这是因为我的路由选择了微软的axd文件而没有正确发送javascript。 我做了一些研究,发现我可以使用Routes.IgnoreRoute ,这应该允许我忽略下面的Routes.IgnoreRoute : Routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”); 但是,当我将该行添加到我的Global.asax时,我收到此错误: CS1061: ‘System.Web.Routing.RouteCollection’ does not contain a definition for ‘IgnoreRoute’ and no extension method ‘IgnoreRoute’ accepting a first argument of type ‘System.Web.Routing.RouteCollection’ could […]

登录后如何更改路由到用户名?

在用户登录之前,路由是: localhost:54274/Home localhost:54274/Home/About localhost:54274/Home/Contact localhost:54274/Home/Login localhost:54274/Home/Register 用户登录后,路由为: 1. localhost:54274/Project 2. localhost:54274/Project/Create 3. localhost:54274/Project/Edit/1 4. localhost:54274/Project/Delete/2 5. localhost:54274/Project/1/Requirement 6. localhost:54274/Project/1/Requirement/Create 7. localhost:54274/Project/1/Requirement/Edit/3 8. localhost:54274/Project/1/Requirement/Delete/4 我想在用户登录后将路由更改为用户名。例如,用户名为hendyharf。 1. localhost:54274/hendyharf/Project 2. localhost:54274/hendyharf/Project/Create 3. localhost:54274/hendyharf/Project/Edit/1 4. localhost:54274/hendyharf/Project/Delete/2 5. localhost:54274/hendyharf/Project/1/Requirement 6. localhost:54274/hendyharf/Project/1/Requirement/Create 7. localhost:54274/hendyharf/Project/1/Requirement/Edit/3 8. localhost:54274/hendyharf/Project/1/Requirement/Delete/4 我的项目的控制器只有3个控制器: HomeController , ProjectController和RequirementController 我的RouteConfig.cs仍处于默认状态 public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”); routes.MapRoute( name: “Default”, […]