Tag: url

如何确定任意URL是否与定义的路由匹配

如何判断字符串是否与特定的命名路由匹配? 我有这样的路线: routes.MapRoute( “FindYourNewRental”, “find-your-new-rental/{market}/{community}.html”, new { controller = “FindYourNewRental”, action = “Community” } ); string url = “http://www.website.com/find-your-new-rental/northerncalifornia/sacramento.html” 如何以编程方式判断’url’字符串是否与该路由匹配? 像这样的东西: // matches url with the named route “FindYourNewRental” if (IsRouteMatch(url, “FindYourNewRental”)) { // do something } public bool IsRouteMatch(string url, string routeName) { // How do I code this function }

获取用户在浏览器中输入的确切URL

我想获得用户输入浏览器的确切url。 当然我总是可以使用像Request.Url.ToString()这样的东西但是在下列情况下这不能给我我想要的东西: http://www.mysite.com/rss 使用上面的URL, Request.Url.ToString()会给我的是: http://www.mysite.com/rss/Default.aspx 有谁知道怎么做到这一点? 我已经尝试过了: Request.Url Request.RawUrl this.Request.ServerVariables[“CACHE_URL”] this.Request.ServerVariables[“HTTP_URL”] ((HttpWorkerRequest)((IServiceProvider)HttpContext.Current).GetService(typeof(HttpWorkerRequest))).GetServerVariable( “CACHE_URL”) ((HttpWorkerRequest)((IServiceProvider)HttpContext.Current).GetService(typeof(HttpWorkerRequest))).GetServerVariable( “HTTP_URL”)

使用http:\\ URL的WPF图像UriSource和数据绑定

我在WPF用户控件中显示带有Web URL的图像时遇到问题。 我已经解决了2008年8月在本网站上提出的类似问题的所有建议( 图像UriSource和数据绑定 ),但这些建议都没有奏效。 我想做的是: ImageFilePathUri是一个从字符串路径创建的Uri: public Uri ImageFilePathUri { get { return new Uri(this.ImageFilePath); } } } 这样就必须设置“Property’UriSource’或属性’StreamSource’。” 错误如预期。 我也尝试过使用值转换器: public class ImageConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var image = new BitmapImage(); image.BeginInit(); if (value != null) { image.UriSource = new Uri((string)value); } […]

ASP.NET Web API中的可选查询字符串参数

我需要实现以下WebAPI方法: /api/books?author=XXX&title=XXX&isbn=XXX&somethingelse=XXX&date=XXX 所有查询字符串参数都可以为null。 也就是说,调用者可以指定从0到所有5个参数。 在MVC4 beta中我曾经做过以下事情: public class BooksController : ApiController { // GET /api/books?author=tolk&title=lord&isbn=91&somethingelse=ABC&date=1970-01-01 public string GetFindBooks(string author, string title, string isbn, string somethingelse, DateTime? date) { // … } } MVC4 RC不再像这样了。 如果我指定少于5个参数,它会回复404说: 未在与请求匹配的控制器“Books”上找到任何操作。 什么是正确的方法签名,使其行为像以前一样,而不必在URL路由中指定可选参数?

ASP.NET MVC – 路由 – 具有文件扩展名的操作

有没有办法实现调用URL http://mywebsite/myarea/mycontroller/myaction.xml这基本上“假”请求文件但结果将是一个动作操作,将服务于动态创建的文件? 我试过这个: context.MapRoute( “Xml_filename”, “Xml/{controller}/{action}.xml” ); 但是,只要URL中存在filextension,路由就会失败并且表现就像我直接请求文件一样。 我怀疑这可能是因为使用扩展名更少的url处理程序。 谢谢你的任何建议。 的Jakub

从浏览器获取URL到C#应用程序

如何使用C#.NET windows窗体应用程序从正在运行的Chrome或Opera实例中获取url? 谢谢!

如何从Chrome和Firefox获取打开网页的url?

我正在编写一个系统托盘应用程序,需要检查基于内部网络的应用程序是否已打开。 我可以使用以下方法检查IE: SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows(); string filename; bool sdOpen = false; foreach (SHDocVw.InternetExplorer ie in shellWindows) { filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower(); if (filename.Equals(“iexplore”)) { string[] urlParts = (ie.LocationURL.ToString()).Split(‘/’); string website = urlParts[2]; if (website == “myApp:8080”) { sdOpen = true; }; } } if (sdOpen) { Console.WriteLine(“App is open”); } else { Console.WriteLine(“App is […]