我正在尝试使用API控制器在ASP.NET MVC 4 Web应用程序内部工作.但是,每个请求都会导致404,我很难过.:/
我从项目模板定义的标准API控制器路由如下:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
Run Code Online (Sandbox Code Playgroud)
在Global.asax中调用注册:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
// Register API routes
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
Run Code Online (Sandbox Code Playgroud)
我有一个这样的基本API控制器:
namespace Website.Controllers
{
public class FavoritesController : ApiController
{
// GET api/<controller>
public IEnumerable<string> Get()
{
return new [] { "first", "second" };
}
// PUT api/<controller>/5
public void Put(int id)
{ …Run Code Online (Sandbox Code Playgroud) 我正在研究为Azure上托管的Web应用程序使用性能和监视工具.
我想知道微软的Application Insights和New Relic之间的主要区别是什么?
谢谢.
Android Studio是一个开源项目吗?如果是,我在哪里可以得到它的源代码?
我们可以为Android Studio添加插件吗?
适用于Android Studio的API在哪里?
我正在尝试style使用HtmlAgilityPack创建一个代码段来删除所有属性而不管标记.
这是我的代码:
var elements = htmlDoc.DocumentNode.SelectNodes("//*");
if (elements!=null)
{
foreach (var element in elements)
{
element.Attributes.Remove("style");
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我没有坚持下去?如果我element立刻看了看对象Remove("style").我可以看到style属性已被删除,但它仍然出现在DocumentNode对象中.:/
我感觉有点傻,但它似乎对我来说?有人用HtmlAgilityPack做过这个吗?谢谢!
更新
我将我的代码更改为以下内容,并且它正常工作:
public static void RemoveStyleAttributes(this HtmlDocument html)
{
var elementsWithStyleAttribute = html.DocumentNode.SelectNodes("//@style");
if (elementsWithStyleAttribute!=null)
{
foreach (var element in elementsWithStyleAttribute)
{
element.Attributes["style"].Remove();
}
}
}
Run Code Online (Sandbox Code Playgroud) 在Firefox和Chrome中单击PDF链接时,有时会打开该文件以进行浏览器浏览,有时会提示"另存为"对话框.
如果我想强制链接始终提示下载,我可以使用下载 HTML5属性.
但是,我想做相反的事情.即,强制链接始终在浏览器中查看.
逆下载属性的排序.有这样的事吗?:)
我更喜欢在提供PDF文档时不修改响应头 - 我希望能够在标记中指定浏览器行为应该是什么.
谢谢!
我有一个ContentPage需要一些“繁重的工作”才能显示其数据。
因此,我的想法是ActivityIndicator在页面上显示可见的内容,直到数据准备好显示为止。
我正在尝试找出一个合适的事件来用于此目的。
我无法使用该Appearing事件,因为该事件发生在页面可见之前。
Loaded对于像或 之类的事件也是如此NavigatedTo,因为它们都会在页面可见之前触发。
所以,我的问题是:在页面加载并对用户可见后,是否有合适的事件来执行某些长时间运行的任务?
编辑:长时间运行的操作是async,但似乎页面上的数据绑定CollectionView是导致页面加载时感知滞后的原因,这就是为什么我想推迟数据绑定,直到页面加载随着旋转可见ActivityIndicator。
编辑2:我可能一直在寻找转移注意力的东西。UI 卡顿似乎是由模板中加载的某些 SVG 引起的CollectionView。不知道为什么,可能与 PNG 转换有关。不管怎样,我认为我实际上并不需要我最初寻找的活动类型。
我试图Entry在页面加载时将焦点设置到控件上以自动触发键盘。
但是,当Entry控件接收焦点(插入符号闪烁)时,如果在Loaded事件期间完成,则键盘不会出现。
如果仅在Appearing事件中完成,插入符号甚至不会出现。
我的页面有一个Entry类似:
<StackLayout>
<Entry x:Name="RoundsEntry" Keyboard="Numeric" />
</StackLayout>
Run Code Online (Sandbox Code Playgroud)
在后面的代码中,我在Loaded事件期间设置焦点:
public RoundsPage()
{
InitializeComponent();
Loaded += RoundsPage_Loaded;
// For Shell navigation, the Appearing event makes more sense,
// as page is only loaded once, but we want the Entry control
// to receive focus every time the user returns to the page.
Appearing += RoundsPage_Loaded;
}
private void RoundsPage_Loaded(object? sender, EventArgs e)
{
RoundsEntry.Focus();
}
Run Code Online (Sandbox Code Playgroud)
手动点击Entry …
我想获得支持呈现特定模型类型的所有视图的列表.
伪代码:
IEnumerable GetViewsByModelType(Type modelType)
{
foreach (var view in SomeWayToGetAllViews())
{
if (typeof(view.ModelType).IsAssignableFrom(modelType))
{
yield return view; // This view supports the specified model type
}
}
}
Run Code Online (Sandbox Code Playgroud)
换句话说,鉴于我有一个MyClass模型,我想找到支持渲染它的所有视图.即@model类型为MyClass的所有视图,或其继承链中的类型.
为了在多个环境中支持Application Insights,我们将按照此帖中的建议以编程方式设置Instrumentation Key.
我们已将<InstrumentationKey>ApplicationInsights.config留空,而是在web.config中添加了一个应用程序设置:
<add key="ApplicationInsightsInstrumentationKey" value="1234-5678-9xxx" />
Run Code Online (Sandbox Code Playgroud)
在Application_Start中,我们执行以下操作来设置检测密钥:
var instrumentationKey = ConfigurationManager.AppSettings["ApplicationInsightsInstrumentationKey"];
if (string.IsNullOrWhiteSpace(instrumentationKey))
{
throw new ConfigurationErrorsException("Missing app setting 'ApplicationInsightsInstrumentationKey' used for Application Insights");
}
TelemetryConfiguration.Active.InstrumentationKey = instrumentationKey;
new TelemetryClient().TrackEvent("Application started");
Run Code Online (Sandbox Code Playgroud)
但是,这会产生一个例外,说" TelemetryChannel必须在它发送遥测之前进行初始化 ".
谷歌搜索此异常消息不会产生任何结果,但我想在跟踪事件之前还需要一些其他内容吗?
我正在尝试实现Azure Web应用程序的零停机部署,其中数据库架构更新需要作为部署的一部分应用.
我有以下设置:
具有production-db连接字符串的生产 Web应用程序.
使用staging-db连接字符串暂存部署槽.
我的伪部署过程类似于:
换句话说,在热交换之后,我希望新代码和更新的数据库都是实时的.
如果此时出现问题,我可以再次交换插槽,使旧的生产应用程序(及其数据库)生效.
据我所知,当我交换插槽时,应用程序将使用生产槽的连接字符串,重新启动应用程序并强制我在更新的代码生效后应用数据库架构更新.
我希望我能正确地描述这一点.:)这似乎应该是一个相当常见的场景?
非常感谢任何帮助或指示!
PS.我在数据库架构更改时查看了Azure无缝升级,但该答案无效,因为我无法在不影响应用程序的情况下应用架构更新.
编辑:只是一个想法:也许我应该跳过将连接字符串作为门户设置,而只是将其保留在web.config中.这样,在交换时,应用程序将不需要重新启动,并且由于web.config将包含在交换中,新的生产槽将使用更新的数据库.
编辑2:我认为当应用程序设置或连接字符串在插槽之间不同时,我错误地认为应用程序重新启动.看来我确实可以为部署插槽设置不同的连接字符串(指向数据库副本),然后在没有重新启动的情况下进行交换,从而影响网站访问者.
azure ×3
asp.net-mvc ×2
c# ×2
html ×2
maui ×2
asp.net ×1
database ×1
deployment ×1
html-parsing ×1
html5 ×1
hyperlink ×1
newrelic ×1
razor ×1
reflection ×1