如何在Asp.Net 5 MVC 6中检测用户是否在移动设备上?
在以前的版本中 Asp MVC可以这样做:
Request.Browser.IsMobileDevice
Run Code Online (Sandbox Code Playgroud)
问题是名称空间System.Web不被使用Asp.Net 5.
Request控制器操作中的变量现在是类型Microsoft.AspNet.Http.HttpRequest,旧版本是类型System.Web.HttpRequestBase.
Microsoft.AspNet.Http.HttpRequest不包含该Browser属性.我试着浏览其他属性,但没有找到任何东西.
编辑:根据要求,一些资源证明Asp.Net 5不再使用System.Web.来自Asp.Net文档
ASP.NET 5不再基于System.Web.dll,而是基于一组精心设计且考虑周全的NuGet包,允许您优化您的应用程序以满足您的需求.
我是ASP.NET的新手,我正在尝试发布一个Web应用程序.我尝试过使用2个不同的主机进行Web部署,但不断收到错误: -
找不到匹配命令"dotnet-bundle"的可执行文件
这有什么关系?
Project.Json
{
"dependencies": {
"Bitly.Net": "0.0.6",
"BitlyAPI": "1.0.3",
"BundlerMinifier.Core": "2.2.281",
"Common.Logging": "3.4.0-Beta2",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.1",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Routing": "1.0.1",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"Parse": "1.7.0",
"Spring.Social.Twitter": "2.0.0-M1",
"Stormpath.AspNetCore": "0.7.0"
},
"tools": {
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"net46": {
"frameworkAssemblies": {
}
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"publishOptions": …Run Code Online (Sandbox Code Playgroud) 我有两个ListView和GridView按钮.为了在这两个按钮之间切换,我写了JQuery,如下所示 -
<script type="text/javascript">
$(document).ready(function () {
$("button.switcher").bind("click", function (e) {
e.preventDefault();
var theid = $(this).attr("id");
var theitems = $("ul#items");
var classNames = $(this).attr('class').split(' ');
if ($(this).hasClass("active")) {
// if currently clicked button has the active class
// then we do nothing!
return false;
} else {
// otherwise we are clicking on the inactive button
// and in the process of switching views!
if (theid == "gridview") {
$(this).addClass("active");
$("#listview").removeClass("active");
// remove the list view and change to grid …Run Code Online (Sandbox Code Playgroud) 我正在使用完整的 .NET 框架 4.6.1 模板构建 asp.net 核心 Web 应用程序,如下所示-
我的 project.json 显示-
"frameworks": {
"net461": { }
},
Run Code Online (Sandbox Code Playgroud)
我想使用EF6(不是 EF 核心),因此使用此命令使用 NuGet 包管理器安装实体框架 -
Install-Package Entityframework
Run Code Online (Sandbox Code Playgroud)
Project.json 添加了这个条目-
"EntityFramework": "6.1.3",
Run Code Online (Sandbox Code Playgroud)
当我尝试使用以下命令创建 DBcontext 和模型时:
Scaffold-DbContext "Server=XXXXX;Database=XXXXXXX;User Id=XXXXXXX;password=XXXXXXX" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -t TABLENAME
Run Code Online (Sandbox Code Playgroud)
它抛出以下错误:
Scaffold-DbContext :术语“Scaffold-DbContext”不被识别为 cmdlet、函数、脚本文件或可运行程序的名称。
检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。
据我了解(因为我有 Powershell v3.0 和 .NET core 1.0.1),我的 project.json 中缺少其余的 EF 工具和依赖项。那么我需要在 project.json 中添加哪些工具和依赖项才能使用 EF6(不是 EF 核心)?
我可以看到的一些选项如下所示。但不确定哪一个适合 EF6
“EntityFramework.MicrosoftSqlServer”:
“EntityFramework.SqlServer”:
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final"
entity-framework entity-framework-6 asp.net-core-mvc asp.net-core