我正在使用ASP.NET 5 MVC6 RC1和Visual Studio 2015 Update 1
我想在视图(.cshtml)和actionresult(控制器方法)之间快速导航.
但是我找不到这样的选择
以前的stackoverflow解决方案不起作用
间歇性代理导致我的页面被我部署的asp.net核心站点缓存.Web服务器没有缓存页面.
我添加了请求和响应缓存,以防止此代理导致的任何缓存
在我的 Startup.cs
app.UseStaticFiles();
app.UseIdentity();
app.Use(async (context, next) =>
{
context.Response.Headers.Append("Cache-Control", "no-cache");
context.Response.Headers.Append("Cache-Control", "private, no-store");
context.Request.Headers.Append("Cache-Control", "no-cache");
context.Request.Headers.Append("Cache-Control", "private, no-store");
await next();
});
Run Code Online (Sandbox Code Playgroud)
我可以在fiddler中看到,我的页面以及javascript文件,css文件和图像文件中都没有添加缓存标头.
我如何限制这个没有缓存标题只适用于asp.net mvc页面所以这些没有缓存标题不会出现在fiddler中的非页面文件,如js,css和图像文件
有没有办法让HTTP请求css和js文件不检查服务器上是否存在每个请求的文件,而只是浏览器版本用于第一次获取这些文件.我问的原因是,在重负载(1000个用户)我在Fiddler我发现我为我的css,js和图像文件得到了HTTPGET的404错误,所以我试图限制对这些资源的请求数量.当请求成功(没有加载)时,我得到304个响应(未修改).是否有办法告诉浏览器不首先发出请求并使用本地缓存版本.
我有一个ASP.NET Core RTM针对的Web应用程序 .net framework 4.52
在我的 project.json
"frameworks": {
"net452": {}
},
Run Code Online (Sandbox Code Playgroud)
当我将它发布到一个文件夹时,它会创建一个MyWebApplication.exe,当我在浏览器中访问应用程序时,运行exe.
我需要将网站发布到具有Windows Server 2012和的Web服务器IIS8
我通过VPN共享文件夹访问网站部署目录.
我第一次将网站发布到它正常工作的文件夹.我访问网站网址并加载网站.但是,当我想在更改和复制文件后重新发布网站时,它告诉我MyWebApplication.exe正在使用并且发布失败.
我知道如何解决这个问题的唯一方法是在发布之前杀死MyWebApplication.exeWeb服务器上的任务管理器.但是,由于我只能通过共享目录访问该服务器,因此无法实现.
有了ASP.NET 4网站,我没有这个问题.
随着ASP.NET CORE RC1我还因为它是使用没有问题dnx虽然HTTPPlatformHandler这让我不必终止该网站复制dnx.exe.我只是不得不触摸web.config,网站将重新启动.
我的问题是:
有没有办法复制/发布已部署的站点的新更改版本(FTP或通过共享文件夹访问)?
有没有办法停止网站,例如MyWebApplication.exe通过FTP或共享文件夹访问从Web服务器上卸载内存?
我有以下课程
public static class MyClass
{
public static double Converter(int mpg)
{
return Math.Round((double)mpg / ((double)36 / 12.74), 2);
}
}
Run Code Online (Sandbox Code Playgroud)
和NUnit单元测试
[TestFixture]
public class ConverterTests
{
[Test]
public void Basic_Tests()
Assert.AreEqual(8.50, MyClass.Converter(24));
}
}
Run Code Online (Sandbox Code Playgroud)
我的单元测试失败了
Expected: 8.5d
But was: 8.4900000000000002d
Run Code Online (Sandbox Code Playgroud)
当我调试方法返回8.49时,单元测试从哪里得到长数字,最后是2?
我使用ASP.NET 5/ ASP.NET Core与EF7/EF Core
我有以下使用ASP.NET 5的依赖项注入的存储库类
using Microsoft.Data.Entity;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MyNamespace
{
public class PersonRepository :IPersonRepository
{
private MyDbContext _db;
public MyRepository(MyDbContext db)
{
_db = db;
}
public async Task<IEnumerable<Person>> Search()
{
var table = from p in _db.Persons
select p;
return await table.ToListAsync();
}
}
public interface IPersonRepository
{
Task<IEnumerable<Person>> Search();
}
}
Run Code Online (Sandbox Code Playgroud)
从ASP.NET MVC控制器调用,我可以成功调用search并获取数据。
public class PersonController : Controller
{
private IPersonRepository _personRepository;
public PersonController …Run Code Online (Sandbox Code Playgroud) asp.net-mvc entity-framework dependency-injection repository-pattern asp.net-core-mvc
我有一个项目ASP.NET 5 RC1,我曾经在我的 HTMLHelper 静态方法中从 HtmlHelper 上下文中获取 urlHelper
public static IHtmlContent MyHtmlHelperMethod<TModel, TResult>(
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression)
{
//get the context from the htmlhelper and use it to get the urlHelper as it isn't passed to the method from the view
var urlHelper = GetContext(htmlHelper).RequestServices.GetRequiredService<IUrlHelper>();
var controller = htmlHelper.ViewContext.RouteData.Values["controller"].ToString();
string myLink;
if (htmlHelper.ViewContext.RouteData.Values["area"] == null)
{
myLink= urlHelper.Action("index", controller);
} else
{
string area = htmlHelper.ViewContext.RouteData.Values["area"].ToString();
myLink = urlHelper.Action("index", controller, new { area = area }); …Run Code Online (Sandbox Code Playgroud) 我创建了一个新的类库(.Net Core),并希望添加该包Microsoft.EntityFrameworkCore.Tools.DotNet 1.0.0.但是我拒绝了,我收到以下错误
严重级代码说明项目文件行抑制状态错误包"Microsoft.EntityFrameworkCore.Tools.DotNet 1.0.0"具有项目"MyVS2017Project"不支持的包类型"DotnetCliTool".0
我也在类库(.Net Framework)中尝试过它
使用Package Manager控制台命令时出现相同的错误消息
安装包Microsoft.EntityFrameworkCore.Tools.DotNet
我在ASP.NET Core 2 Web应用程序中使用JWT令牌
如果JWT令牌失败,我仍然希望命中控制器方法,但ASP.NET Identity User对象将只为null.目前,如果身份验证失败,则不会输入控制器方法,因此我无法在方法中应用逻辑来处理我想要作为来宾处理的非身份验证用户,而不是阻止它们.
我的代码:
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication()
.AddJwtBearer(cfg =>
{
cfg.TokenValidationParameters = new TokenValidationParameters()
{
ValidIssuer = _config["Tokens:Issuer"],
ValidAudience = _config["Tokens:Audience"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Tokens:Key"]))
};
});
Run Code Online (Sandbox Code Playgroud)
用户登录时
private IActionResult CreateToken(ApplicationUser user, IList<string> roles)
{
var claims = new List<Claim>
{
new Claim(JwtRegisteredClaimNames.Sub, user.Id.ToString()),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim(JwtRegisteredClaimNames.UniqueName, user.UserName)
};
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Tokens:Key"]));
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
var token = new JwtSecurityToken(
_config["Tokens:Issuer"],
_config["Tokens:Audience"],
claims.ToArray(),
expires: …Run Code Online (Sandbox Code Playgroud) c# jwt asp.net-core asp.net-core-webapi asp.net-core-identity
如果我在 SQL Server Management Studio 中键入文本,那么当我键入单个字符时它不会响应'。如果我输入两次,那么它会显示我两个彼此相邻,例如
\n\n\n\n\n”
\n
'由于查询中的字符串是用单引号标识的,因此必须按两次然后使用退格键才能获取单引号,这确实令人沮丧。
\n\n另外,如果我输入'A例如它显示为
\n\n\n\n\n\xc3\x81
\n
这个问题大约两周前开始出现。以前从来都不是问题
\n我正在使用jquery.validate v1.14.0JörnZaefferer
<script src="~/lib/jquery-validation/dist/jquery.validate.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
Run Code Online (Sandbox Code Playgroud)
我有一个项目,所有验证工作正常.如果未填充必填字段,则客户端验证会在表单汇总之前将其选中.
然而,我将所有这些形式移动到boostrap模态,并且页面的表单通过ajax调用在模态内动态加载.在此更改之后,我的客户端验证永远不会触发,我还注意到验证插件不像novalidate="novalidate"以前那样将标记添加到表单中.
这是我的代码简化
然后我使用以下jquery,因为我想捕获所有表单提交并执行一些额外的逻辑:
$(document).on('submit', '.formDetail', function (e) {
e.preventDefault();
//added this to see if it would throw error but it doesn't
var form = $(".formDetail");
form.validate();
//this is always true
if ($(this).valid()) {
$.ajax({
processData: false,
contentType: false,
data: new FormData(this),
type: $(this).attr('method'),
url: $(this).attr('action'),
success: function (data) {
//other logic
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
如果String1留空并且我提交并逐步执行javascript控制台'($(this).valid())'是alwasy true.如果我改变它($(".formDetail").valid()) 的结果是相同的,即总是如此true.
它也没有像我在切换到动态ajax模式窗体之前那样在HTTP POST之前在屏幕上显示错误消息.
我怎样valid()才能上班.单步执行代码时,我的控制台中没有javascript错误,并且 …
ajax jquery jquery-validate unobtrusive-validation bootstrap-modal
我有一个选择的反应形式
<select [(ngModel)]="user.positionId" name="positionId" class="custom-select form-control form-control-sm" required
formControlName="positionId"
[ngClass]="{
'is-invalid': positionId.invalid && (positionId.dirty || positionId.touched),
'is-valid': positionId.valid && (positionId.dirty || positionId.touched)
}">
<option value="">--Select--</option>
<option *ngFor="let position of user.positionSelectList" value="{{position.value}}">
{{position.text}}
</option>
</select>
Run Code Online (Sandbox Code Playgroud)
它获得传递的positionId,它是可为空的数字
export class User{
id: string;
userName: string;
positionId?: number;
}
Run Code Online (Sandbox Code Playgroud)
当我将数字值作为positionId传递时,上述方法有效。
但是,当它传递一个空值时,则不会选择默认选项“ --Select--”,但是会在其上方显示一个附加的空白选项。
我尝试过的。
<option value=null>--Select--</option>
Run Code Online (Sandbox Code Playgroud)
和
<option value=udefined>--Select--</option>
Run Code Online (Sandbox Code Playgroud)
但这给出了与未选择“ --Select--”相同的结果
我不希望将硬编码数字值设置为固定数字,例如-1,因为我需要进行必要的验证,如果未选择,则需要空白值。
我将我的ASP.NET Core,EF Core类库解决方案升级到Visual Studio 2017.
但是,当我想运行Add-Migration等迁移命令时,我收到以下警告.
实体框架核心和实体框架6都已安装.实体框架核心工具正在运行.为Entity Framework 6使用'EntityFramework\Update-Database'.
但是我没有安装EF 6
我的csproj
...
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.1" />
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
<PackageReference Include="System.Collections" Version="4.3.0" />
<PackageReference Include="System.Linq" Version="4.3.0" />
<PackageReference Include="System.Runtime" Version="4.3.0" />
<PackageReference Include="System.Threading" Version="4.3.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud) 根据我的理解,数组总是可以为空的.但是,当我想将数组的大小调整为更大的大小时,我希望它在新元素中返回null.但它返回0;
例:
int[] myArray = { 1, 2, 3 };
Array.Resize(ref myArray, 100);
int? shouldBeNull = myArray[3];
Run Code Online (Sandbox Code Playgroud)
如何使myArray [3]返回null而不是像目前那样返回0?
asp.net-core ×4
c# ×4
.net-core ×1
ajax ×1
angular5 ×1
arrays ×1
asp.net-mvc ×1
deployment ×1
iis ×1
iis-8 ×1
jquery ×1
jwt ×1
sql-server ×1
ssms ×1
unit-testing ×1