在ASP.NET Core 2.0中,关于它如何查找视图,一些非显而易见的(或显然不是通过Google-foo找到的)发生了变化.与通用区域route("{area:exists}/{controller=Home}/{action=Index}/{id?}")相关联的所有视图将执行其操作并按预期查找其关联视图,但如果我指定不太通用的路径,"Forums/Recent/{page?}"则不会找到该视图.我无法强调,控制器动作中的代码会触发,因此它正确地使用了路径.它只是没有在正确的地方寻找视图.它只是在共享的地方寻找:
InvalidOperationException: The view 'Recent' was not found. The following locations were searched:
/Areas/Forums/Views/Shared/Recent.cshtml
/Views/Shared/Recent.cshtml
Run Code Online (Sandbox Code Playgroud)
它没有查看/Areas/Forums/Views/Forum/Recent.cshtml,按照惯例,它与控制器匹配.
如果重要的话,我的控制器与视图不在同一个项目中.同样,控制器操作会执行,但它甚至不会在视图的正确位置查找.它在v1.1中正常工作.
我正在尝试编写一个封装WCF调用的类(客户端是Silverlight,如果重要的话).这一切都在游泳,但我不知道如何陷阱连接失败,好像服务器不会响应.似乎在ChannelFactory生成的代码中某处发生了一些工作,但我不确定.也欢迎一般代码审查.:)
围绕创建通道的底线,或try/catch中的begin或async结果委托不会捕获失败的连接.我想让那个catch运行ServiceCallError事件.
public class ServiceCaller : IDisposable
{
private IFeedService _channel;
public ServiceCaller()
{
var elements = new List<BindingElement>();
elements.Add(new BinaryMessageEncodingBindingElement());
elements.Add(new HttpTransportBindingElement());
var binding = new CustomBinding(elements);
var endpointAddress = new EndpointAddress(App.GetRootUrl() + "Feed.svc");
_channel = new ChannelFactory<IFeedService>(binding, endpointAddress).CreateChannel();
}
public void MakeCall(DateTime lastTime, Dictionary<string, string> context)
{
AsyncCallback asyncCallBack = delegate(IAsyncResult result)
{
var items = ((IFeedService)result.AsyncState).EndGet(result);
if (ItemsRetrieved != null)
ItemsRetrieved(this, new ServiceCallerEventArgs(items));
};
_channel.BeginGet(lastTime, context, asyncCallBack, _channel);
}
public event ItemsRetrievedEventHandler ItemsRetrieved;
public event ServiceCallErrorHandler ServiceCallError; …Run Code Online (Sandbox Code Playgroud) 我想这很明显,但在我提交错误报告之前,我想知道我做错了.我使用ASP.NET MVC3 RC和Razor有这个视图:
<div class="miniProfile">
Joined: @FormatTime(Model.Joined)<br />
@if (!String.IsNullOrWhiteSpace(Model.Location)) {
Location: @Model.Location<br />
}
Posts: @Model.PostCount<br />
@Html.ActionLink("Full Profile", "ViewProfile", new { id = Model.UserID }, new { target = "_blank" }) |
@Html.ActionLink("Send Private Message", "SendNew", "PrivateMessages", new { id = Model.UserID }) |
@Html.ActionLink("Send E-mail", "Send", "Email", new { id = Model.UserID })
@if (!String.IsNullOrWhiteSpace(Model.Web)) {
| <a href="@Model.Web" target="_blank">Visit user Web site: @Model.Web</a>
}
</div>
Run Code Online (Sandbox Code Playgroud)
它在"位置"和最后一个条件的管道中窒息.如果我插入一些<text>标签,它的工作原理如下:
<div class="miniProfile">
Joined: @FormatTime(Model.Joined)<br />
@if (!String.IsNullOrWhiteSpace(Model.Location)) {
<text>Location: </text>@Model.Location<br …Run Code Online (Sandbox Code Playgroud) 对我来说,这个真正让人头晕目眩......
var matches = Regex.Matches("<p>test something<script language=\"javascript\">alert('hello');</script> and here's <b>bold</b> and <i>italic</i> and <a href=\"http://popw.com/\">link</a>.</p>", "</?(?!p|a|b|i)\b[^>]*>");
Run Code Online (Sandbox Code Playgroud)
正则表达式应该捕获任何不是p,a,b或i的HTML标记(打开或关闭).我已经将输入字符串和正则表达式插入到无数的测试页面中,并且每个测试页面都会返回脚本标记(打开和关闭)作为匹配项.但它在代码中绝对不起作用.matches变量的计数为0.
我错过了一些非常明显的东西吗?
做这项工作的机制并不难,但测试它有点奇怪.方案是我想根据基本控制器的用户属性(IPrincipal对象)将一些基本用户数据转储到视图数据中,以便母版页始终拥有它.我需要访问我的IUserManager(服务类),它由控制器工厂中的自定义DI提供.模拟用户对测试没有问题.但是,对基本控制器中的每个操作实现此操作的最简单方法是通过重写OnAuthorization方法来完成此操作.然后基类看起来像这样:
public abstract class BaseController : Controller
{
public BaseController(IUserManager userManager)
{
UserManager = userManager;
}
public IUserManager UserManager { get; private set; }
protected override void OnAuthorization(AuthorizationContext filterContext)
{
base.OnAuthorization(filterContext);
UserManager.SetupUserViewData(User, ViewData);
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,我无法在测试中找到使OnAuth方法触发的方法.我想在我的模拟UserManager中验证是否调用了SetupUserViewData.我没有使用自定义过滤器,因为我没有完整的依赖注入框架(过滤器需要获取IUserManager).
有什么建议?由于这将在任何地方使用,我想让测试正确.
我有一个SQL Server数据库,这是复制的最终结果.换句话说,它只是副本.我想使用Management Studio或BACPAC文件将此数据库迁移到SQL Azure.尝试这个我得到了我期望的东西,例如需要聚集索引,但我坚持的是每个表上的主键(并且有很多)都有以下错误:
IdentityIsNotForReplication已设置,并且在用作数据包的一部分时不受支持.
好吧,很酷,但这是围绕架构的.NET抽象的属性,据我所知,我不能从T-SQL改变.我有点卡住了!
我从一开始就一直在为ASP.NET编写代码,今天我遇到了一些我以前从未见过的东西.通常情况下,我通过期待"\ r \n"来查找C#中的换行符(例如,当从textarea发布在ASP.NET中时).现在我正在使用MVC框架,来自textarea的线路文本只有"\n"用于换行符.
在旧学校TextBox控件中是否有一些事情可以规范换行符?由于MVC只是按原样使用表单数据,这是正常的吗?很想得到一些见解.
asp.net-mvc ×3
asp.net ×2
c# ×2
.net ×1
asp.net-core ×1
azure ×1
controller ×1
master-pages ×1
newline ×1
razor ×1
regex ×1
sql-server ×1
wcf ×1
wcf-client ×1