我有两个冲突的动作方法.基本上,我希望能够使用两个不同的路径来获取相同的视图,可以是项目的ID,也可以是项目的名称及其父项(项目可以在不同的父项中具有相同的名称).搜索项可用于过滤列表.
例如...
Items/{action}/ParentName/ItemName
Items/{action}/1234-4321-1234-4321
Run Code Online (Sandbox Code Playgroud)
这是我的行动方法(还有Remove行动方法)......
// Method #1
public ActionResult Assign(string parentName, string itemName) {
// Logic to retrieve item's ID here...
string itemId = ...;
return RedirectToAction("Assign", "Items", new { itemId });
}
// Method #2
public ActionResult Assign(string itemId, string searchTerm, int? page) { ... }
Run Code Online (Sandbox Code Playgroud)
以下是路线......
routes.MapRoute("AssignRemove",
"Items/{action}/{itemId}",
new { controller = "Items" }
);
routes.MapRoute("AssignRemovePretty",
"Items/{action}/{parentName}/{itemName}",
new { controller = "Items" }
);
Run Code Online (Sandbox Code Playgroud)
我理解为什么错误发生,因为page参数可以为null,但我无法找出解决它的最佳方法.我的设计开始时很差吗?我已经考虑过扩展Method #1签名以包含搜索参数并将逻辑Method #2移到他们都会调用的私有方法中,但我不相信这会真正解决这种模糊性.
任何帮助将不胜感激.
实际解决方案 …
我有一个ApiController,我想使用电子邮件地址作为请求的ID参数:
// GET api/employees/email@address.com
public CompactEmployee Get(string id) {
var email = id;
return GetEmployeeByEmail(email);
}
Run Code Online (Sandbox Code Playgroud)
但是,我不能让它工作(返回404):
http://localhost:1080/api/employees/employee@company.com
以下所有工作:
http://localhost:1080/api/employees/employee@companyhttp://localhost:1080/api/employees/employee@company.http://localhost:1080/api/employees?id=employee@company.com我已经设置relaxedUrlToFileSystemMapping="true"了我的web.config,详见Phil Haack.
我非常喜欢完整的电子邮件地址,但是任何时候任何其他角色跟着这个时期,请求都会返回404.任何帮助都将非常感谢!
由于缺乏其他选项,我已朝着Maggie建议的方向前进,并使用此问题的答案来创建重写规则,以便在我需要URL中的电子邮件时自动附加尾部斜杠.
<system.webServer>
....
<rewrite>
<rules>
<rule name="Add trailing slash" stopProcessing="true">
<match url="^(api/employees/.*\.[a-z]{2,4})$" />
<action type="Rewrite" url="{R:1}/" />
</rule>
</rules>
</rewrite>
</system.webServer>
Run Code Online (Sandbox Code Playgroud) 仅在发布ASP.NET 5 Web应用程序时执行Gulp任务的最佳方法是什么?我是否需要添加执行Gulp命令的自定义构建事件?
cmd.exe /c gulp -b "C:\Projects\ProjectName\Source\ProjectName.Web" --gulpfile "C:\Projects\ProjectName\Source\ProjectName.Web\Gulpfile.js" publish
Run Code Online (Sandbox Code Playgroud)
或者,最好是否有办法BeforePublish通过Task Runner Explorer 将Gulp任务绑定到目标?
任何建议将非常感激.
有很多关于ReaderWriterLockSlim类的文章,它允许多次读取和单次写入.所有这些(至少我发现的)告诉如何使用它而没有太多解释为什么以及如何工作.标准代码示例是:
lock.EnterUpgradeableReadLock();
try
{
if (test if write is required)
{
lock.EnterWriteLock();
try
{
change the resourse here.
}
finally
{
lock.ExitWriteLock();
}
}
}
finally
{
lock.ExitUpgradeableReadLock();
}
Run Code Online (Sandbox Code Playgroud)
问题是:如果可升级锁只允许一个线程进入其部分,为什么我应该在其中调用EnterWriteLock方法?如果我不这样做会怎样?或者如果不是使用EnterUpgradeableReadLock,我会调用EnterWriteLock并且在不使用可升级锁的情况下写入资源会发生什么?
我正在尝试使用单个Func<T,bool>定义来处理类及其继承者.这就是我所拥有的:
Func<Job, bool> ValidJob =
j => !j.Deleted && !j.OnHold && j.PostDate <= DateTime.Now && j.ExpireDate > DateTime.Now;
public class JobExtended : Job { }
Run Code Online (Sandbox Code Playgroud)
因此,鉴于此,以下工作:
IQueryable<Job> jobs = ...
jobs.Where(ValidJob);
Run Code Online (Sandbox Code Playgroud)
但是,以下内容不是:
IQueryable<JobExtended> jobs = ...
jobs.Where(ValidJob);
Run Code Online (Sandbox Code Playgroud)
我想知道Func<T,bool>在这种情况下是否有可能单身,如果是的话,怎么样?我已经尝试按照建议指定类型参数,但我没有运气.
我想检查一个字符串的第一个字符是否是一个字母.我的正则表达式是:
'/^([a-zA-Z.*])$/'
Run Code Online (Sandbox Code Playgroud)
这不起作用.它出什么问题了?
我正在尝试将Azure AD身份验证添加到我的ASP.NET 5 MVC 6应用程序,并在GitHub上遵循此示例.如果我把推荐的代码放在一个动作方法中,一切正常:
Context.Response.Challenge(
new AuthenticationProperties { RedirectUri = "/" },
OpenIdConnectAuthenticationDefaults.AuthenticationType);
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试使用该[Authorize]属性,我会得到一个立即空的401响应.
如何[Authorize]正确地重定向到Azure AD?
我的配置如下:
public void ConfigureServices(IServiceCollection services) {
...
services.Configure<ExternalAuthenticationOptions>(options => {
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
});
...
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) {
...
app.UseCookieAuthentication(options => {
options.AutomaticAuthentication = true;
});
app.UseOpenIdConnectAuthentication(options => {
options.ClientId = Configuration.Get("AzureAd:ClientId");
options.Authority = String.Format(Configuration.Get("AzureAd:AadInstance"), Configuration.Get("AzureAd:Tenant"));
options.RedirectUri = "https://localhost:44300";
options.PostLogoutRedirectUri = Configuration.Get("AzureAd:PostLogoutRedirectUri");
options.Notifications = new OpenIdConnectAuthenticationNotifications {
AuthenticationFailed …Run Code Online (Sandbox Code Playgroud) action-filter azure-active-directory asp.net-core-mvc openid-connect asp.net-core
http://briancray.com/tests/checkboxes/index.html
实现全选的方法很简单,但并不完美.select all和unselect all工作正常,但当选择all all状态时,如果取消选中一个,则select all也会被选中.如何纠正?
然后

仍然检查"全部检查".如何纠正?
为什么这个正则表达式不起作用?正确的电子邮件地址未通过验证.
<script type="text/javascript">
$(document).ready(function() {
var regex = new RegExp(/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i );
$('#submit').click(function () {
var name = $('input[name=name]');
var email = $('input[name=email]');
var website = $('input[name=website]');
var comment = $('textarea[name=comment]');
if ((!regex.test(email))) {
email.addClass('hightlight');
return false;
} else
email.removeClass('hightlight');
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在我的服务器上安装了一个MongoDB数据库.我的服务器是32Bit,我不能很快改变它.
当你在32Bit架构中使用MongoDB时,你的数据限制为2,5Go,正如MongoDB博客文章中所提到的那样.
问题是我有几个数据库.那么我怎么知道我是否接近这个限制呢?
.net ×3
asp.net-core ×2
asp.net-mvc ×2
c# ×2
javascript ×2
regex ×2
32-bit ×1
dnu ×1
gulp ×1
jquery ×1
lambda ×1
limit ×1
linq ×1
mongodb ×1
publish ×1
validation ×1