我正在我的asp.net-mvc网站上记录错误,我想看看是否有检测用户浏览器信息(名称,版本等),因为看起来人们正在遇到问题,但是因为他们使用的很旧浏览器.如果我知道他们使用的是"不支持"的浏览器,这些信息可以帮助我避免调试时间.
我有一些生成电子邮件的代码,我想要包含电子邮件正文中运行的实际服务器计算机名称.(这是一个集群的Web环境,所以我想知道发送电子邮件的实际机器是什么.)
我知道我可以使用Request.Url.AbsoluteUri,但是这给了我URL(比如www.mysite.com/MyController/Action)而不是原始的实际机器名 - 可能是MACH3234k323.
有没有办法可以获得实际的服务器机器的名称?
如何在Windows 10上配置Web Deploy?应该有用吗?我在Windows 8上找到了有关Web Deploy的信息,但它无法正常工作.它在Windows 10中如何?
我正在使用nopCommerce,我需要添加我唯一的Action Filter,但是,我不想修改核心控制器以避免在发布新更新时覆盖我的代码.
我已经设置了我的动作过滤器:
public class ProductActionFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
if (filterContext.Result is ViewResult)
{
...
}
base.OnActionExecuted(filterContext);
}
}
Run Code Online (Sandbox Code Playgroud)
如果我要修改控制器,我可以添加[ProductActionFilter]到我希望它分配给的操作.
有没有办法可以在不修改控制器的情况下将自定义操作过滤器注册到特定操作?
任何人都可以告诉我,是否有办法让我在global.asax的Application_Start事件中获取我的网站的域名?
通常我只是从Context.Request.ServerVariables ["SERVER_NAME"]中获取它,但这不可用.理想情况下,我还希望从启动应用程序的请求中获取URL.
嗯 - 从下面的答案来看,似乎在IIS7上有所作为.这是新的,现在有设计指南试图阻止你这样做:
我正在使用Newtonsoft.Json将对象解析为json字符串.它会像这样返回一些思考:
{\"code\":-1,\"idName\":\"empty\",\"idValue\":0,\"message\":\"Failed,can not read object from body\"}
Run Code Online (Sandbox Code Playgroud)
它不是一个有效的json字符串我认为,任何人都可以帮我工作?
我想要的是这样的:
{"code":-1,"idName":"empty\",\"idValue\":0,\"message\":\"Failed,can not read object from body\"}
Run Code Online (Sandbox Code Playgroud)
public static class CommonUtility
{
// format response string
public static string FormatResponseString(int code, string idName, long idValue, string message)
{
ResponseString rs = new ResponseString();
rs.code = code;
rs.idName = idName;
rs.idValue = idValue;
rs.message = message;
string json = JsonConvert.SerializeObject(rs);
return json;
}
}
public class ResponseString
{
public int code;
public string idName;
public long idValue;
public string message;
}
Run Code Online (Sandbox Code Playgroud)
编辑:这是来自响应fidder TextView的实际json我可以看到: …
我需要清空IEnumerable列表我尝试了许多像null这样的东西,但没有一个工作
这就是我的模型的样子
public class NewsViewModel
{
public NewsViewModel()
{
this.Categories = new List<Category>();
}
public int NewsId { get; set; }
public string NewsTitle { get; set; }
public string NewsBody { get; set; }
public IEnumerable<Category> Categories { get; set; }
}
if (!string.IsNullOrEmpty(SelectedCategoriesIds))
{
List<Category> stringList = new List<Category>();
stringList.AddRange(SelectedCategoriesIds.Split(',').Select(i => new Category() { CategoryId = int.Parse(i) }));
model.Categories = stringList.AsEnumerable();
}
else
{
model.Categories = null;
}
Run Code Online (Sandbox Code Playgroud)
怎么model.Categories做空?
首先,我想说我是C#的新手,所以这个问题似乎完全偏离了轨道.
我有一组名为ShapeType的枚举:
Cube, Sphere, Rectangle, Ellipse
Run Code Online (Sandbox Code Playgroud)
以及从枚举中返回随机值的方法:
private static ShapeType GetRandomShape()
{
Array values = Enum.GetValues(typeof(ShapeType));
Random random = new Random();
ShapeType randomShape = (ShapeType)values.GetValue(random.Next(values.Length));
return randomShape;
}
Run Code Online (Sandbox Code Playgroud)
每个可枚举的都有相应的具体类.我想知道的问题是,如果你可以使用随机可枚举值randomShape来实例化一个类,有点像这样:
private static Shape GetRandomShape()
{
Array values = Enum.GetValues(typeof(ShapeType));
Random random = new Random();
ShapeType randomShape = (ShapeType)values.GetValue(random.Next(values.Length));
Shape shape = new randomShape(); // *Here use the randomShape-variable as type*
return shape;
}
Run Code Online (Sandbox Code Playgroud)
这可能还是只是一厢情愿的想法?
我试图在特定表格上处理鼠标点击事件,如果鼠标光标落在一组坐标之间,则应触发该事件 - 比方说.
我明白,如果我有一个空的表格,我可以简单地绑定到mousemove事件,然后离开.但实际上可能有多达10个不同的重叠控件,在我的测试应用程序中,mousemove事件仅在光标位于实际表单本身时触发,而不是在其通过子控件时触发.
当设计时存在未知数量的子控件时,是否有人知道如何处理此事件?
我可以使用简单的单行程吗?
我有一个样式,它的 setter 属性名为“Fill”,并以 DrawingBrush 作为其值。我想从中提取 DrawingBrush 以在视图模型中使用。这是我的风格。
<Style x:Key="ICON_STYLE" TargetType="Rectangle">
<Setter Property="Fill">
<Setter.Value>
<DrawingBrush Viewbox="0,0,39.125,39.125" ViewboxUnits="Absolute">
<DrawingBrush.Drawing>
<GeometryDrawing Brush="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=uiEntityViews:ViewModel}, Path=MeSiteColor}" Geometry="F1M19.5625,0.999954C29.8144,0.999954 38.125,9.31053 38.125,19.5625 38.125,29.8142 29.8143,38.1249 19.5625,38.1249 9.31073,38.1249 1,29.8142 1,19.5625 1,9.31053 9.31064,0.999954 19.5625,0.999954z">
<GeometryDrawing.Pen>
<Pen DashCap="Square" EndLineCap="Flat" LineJoin="Round" MiterLimit="10" StartLineCap="Flat" Thickness="2">
<Pen.Brush>
<LinearGradientBrush EndPoint="0.849422,0.849423" StartPoint="0.150577,0.150578">
<GradientStop Color="#FF657783" Offset="0"/>
<GradientStop Color="White" Offset="0.146"/>
<GradientStop Color="#FF2C4758" Offset="1"/>
</LinearGradientBrush>
</Pen.Brush>
<Pen.DashStyle>
<DashStyle/>
</Pen.DashStyle>
</Pen>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
我想按如下方式提取 DrawingBrush -
if (resourceObject is Style)
{
Style iconStyle = …Run Code Online (Sandbox Code Playgroud)