按照此处找到的教程,我无法创建自定义500或404错误页面.如果我输入了错误的网址,该页面会为我提供默认的错误页面.有什么我应该检查,以防止自定义页面显示?
文件目录:
mysite/
mysite/
__init__.py
__init__.pyc
settings.py
settings.pyc
urls.py
urls.pyc
wsgi.py
wsgi.pyc
polls/
templates/
admin/
base_site.html
404.html
500.html
polls/
detail.html
index.html
__init__.py
__init__.pyc
admin.py
admin.pyc
models.py
models.pyc
tests.py
urls.py
urls.pyc
view.py
views.pyc
templates/
manage.py
Run Code Online (Sandbox Code Playgroud)
在mysite/settings.py中我启用了这些:
DEBUG = False
TEMPLATE_DEBUG = DEBUG
#....
TEMPLATE_DIRS = (
'C:/Users/Me/Django/mysite/templates',
)
Run Code Online (Sandbox Code Playgroud)
在mysite/polls/urls.py中:
from django.conf.urls import patterns, url
from polls import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^(?P<poll_id>\d+)/$', views.detail, name='detail'),
url(r'^(?P<poll_id>\d+)/results/$', views.results, name='results'),
url(r'^(?P<poll_id>\d+)/vote/$', views.vote, name='vote'),
)
Run Code Online (Sandbox Code Playgroud)
我可以发布任何其他必要的代码,但是如果我使用错误的网址,我应该如何更改以获取自定义500错误页面?
编辑
解决方案: 我有一个额外的
TEMPLATE_DIRS …Run Code Online (Sandbox Code Playgroud) 有人可以指点我一个资源,可以告诉我如何Object[]在一个powershell函数中传入一个参数?这两个函数都是Cmdlet,它们正在正确导出,但我$Return在第二个函数中看不到该对象.
# Within PowerShell code
$Return = My-Function -Param "value" # $Return is of type Object[]
$ModifiedReturn = My-SecondFunction -Input $Return
Run Code Online (Sandbox Code Playgroud)
这是我的功能定义
function My-SecondFunction
{
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[Object[]]$Input
)
begin {}
process
{
Write-Host "test: $Input" # Does not return anything
}
end {}
}
Run Code Online (Sandbox Code Playgroud) 我目前正在调查为什么 JSON.stringify() 没有正确解析我的对象。这是我试图解析为 JSON 字符串的对象:
var data = [{
name: string,
active: bool,
data: [
value: number,
date: string
]
}]
Run Code Online (Sandbox Code Playgroud)
但是,在我的对象上调用 JSON.stringify() 时,我得到的结果类似于:
/* JSON.stringify(data) */
[{
name: string,
active: bool,
data: [
[Object],
[Object],
...
]
}]
Run Code Online (Sandbox Code Playgroud)
JSON.stringify 是否有细微差别导致这种情况发生?如果它有助于澄清更多细节,我很乐意为我的问题添加更多细节。
有没有办法根据cookie值设置OutputCache的值?
为了简单起见,这是我的方法
[OutputCache(Duration = 600, VaryByParam = "None", VaryByCustom = "ztest")]
public ViewResult Index()
{
return View();
}
Run Code Online (Sandbox Code Playgroud)
我的Global.asax有这个(为了覆盖GetVaryByCustomString方法
public override string GetVaryByCustomString(HttpContext context, string custom)
{
if (custom == "ztest")
{
HttpCookie ztest = context.Request.Cookies["ztest"];
if (ztest != null)
{
return ztest.Value;
}
}
return base.GetVaryByCustomString(context, custom);
}
Run Code Online (Sandbox Code Playgroud)
我可以验证我的浏览器是否有ztest cookie,但是当我调试Index方法时,我每次都会遇到断点(意味着缓存不起作用).
HttpResponse没有出站cookie,所以这一点不适用:https://msdn.microsoft.com/en-us/library/system.web.httpcookie.shareable(v=vs.110).aspx
如果给定的HttpResponse包含一个或多个出站cookie,并且Shareable设置为false(默认值),则将抑制响应的输出缓存.这可以防止包含潜在敏感信息的cookie缓存在响应中并发送到多个客户端.要允许缓存包含cookie的响应,请为响应正常配置缓存,例如使用OutputCache指令或MVC的[OutputCache]属性,并设置所有出站cookie以使Shareable设置为true.
我将在本地网络上演示ASP.NET MVC网站.此应用程序与数据库连接:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-EBC-20141127093222.mdf;Initial Catalog=aspnet-EBC-20141127093222;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
我想如果IIS和每当我在本地运行我的应用程序时都可以使用这个数据库.我在IIS上创建了一个站点 - 它运行的是.NET v4.我的项目住在c:\inetpub\www\ebc.我可以发布网站,但在查看页面时收到此错误:
"建立与SQL Server的连接时发生与网络相关或特定于实例的错误.未找到服务器或无法访问服务器.验证实例名称是否正确以及SQL Server是否配置为允许远程连接.(提供程序: SQL网络接口,错误:50 - 发生本地数据库运行时错误.在LocalDB实例API方法调用中发生意外错误.请参阅Windows应用程序事件日志以获取错误详细信息.
我知道我需要允许通过microsoft sql server manager远程连接到sql server?有没有办法在别处做?
需要将三个表连接在一起。
Table [Package]
ID (int)
ContainerID (int)
Code (string)
Code2 (string)
Table [UserHasPackages]
UserID (Comes from Identity tables) (string)
PackageID (int)
Table [Container]
ID (int)
Name (string)
Description (string)
Run Code Online (Sandbox Code Playgroud)
进入代表我想在视图中显示的对象的视图模型:
public class CustomViewModel
{
public int ID { get; set; }
public string Name { get; set; } // Container.Name
public string Code { get; set; } // Package.Code
public string Code2 { get; set; } // Package.Code2
}
Run Code Online (Sandbox Code Playgroud)
但我在加入时遇到问题:
List<CustomViewModel> list = new List<CustomViewModel>();
list = context.Packages.Join(
context.Containers,
p …Run Code Online (Sandbox Code Playgroud) 这真的让我陷入困境。我为 Visual Studio 安装了 Xamarin,创建了一个空项目并连接到我的 Mac。我模拟 iPhone 并收到此错误
Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Application windows are expected to have a root view controller at the end of application launch
Run Code Online (Sandbox Code Playgroud)
这是由在Main.cs类中调用 UIApplication.Main 引起的
using UIKit;
namespace testapp
{
public class Application
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, …Run Code Online (Sandbox Code Playgroud) 我可以将数组拆分成两个独立的数组,原始数组中的每个元素用":"分隔吗?":"之前的文本转到array1,":"之后的文本转到array2
<cfset tempArr = DeserializeJSON(URL.data) />
<cfset selectList = "" />
<cfloop array=#tempArr# index="i">
<cfset selectList = listappend(selectList,i) />
</cfloop>
Run Code Online (Sandbox Code Playgroud)
现在,这段代码抓住了整个元素,而不是分开.
编辑
示例字符串将是:
FIRST_NAME:鲍勃
first_name进入selectList1 Bob进入selectList2
宏伟的计划同样会有其他领域:
FIRST_NAME:鲍勃
姓氏:Shmo
年龄:27
等等...
编辑:答案
通过使用代码解决了问题
<!---Variables--->
<cfset temp1 = "" />
<cfset temp2 = "" />
<cfset selectList1 = "" /><!---Holds column names for tables--->
<cfset selectList2 = "" /><!---Holds query parameters for column names. Ie,
values for use in the WHERE clause--->
<cfloop array=#tempArr# index="i"><!---Loop through contents of the array--->
<cfset …Run Code Online (Sandbox Code Playgroud) 我有一个查询,我正在返回动态数据,但无法通过 Dapper 检索其文档(https://github.com/StackExchange/Dapper)中列出的值。
他们有这样的代码示例:
var rows = connection.Query("select 1 A, 2 B union all select 3, 4");
Assert.Equal(1, (int)rows[0].A);
Run Code Online (Sandbox Code Playgroud)
但是,当我执行以下操作时,我无法访问查询结果的任何成员:
var query = db.Query("SELECT SUM(UserRating) as 'Sum', AVG(UserRating) as 'Average', COUNT(*) as 'Total' FROM ActivityLogs");
query.FirstOrDefault(); // {{DapperRow, Sum= '3', Average = '3', Total = '1'}}
var sum = query[0].Sum; // error!
Run Code Online (Sandbox Code Playgroud)
错误信息:
错误 CS0021:无法将带有 [] 的索引应用于“对象”类型的表达式
我如何到达我的领域?
我一直在寻找并尝试对.NET Core身份进行更多研究(https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-2.1&tabs=visual -studio%2Caspnetcore2x)和Jwt(json网络令牌)。我一直在使用.NET Core 2.0应用程序中的默认身份作为身份验证/授权,到目前为止,它一直运行良好。
我遇到了一个障碍,我认为这是我对.NET Core身份和jwt的理解的方式。我的应用程序具有MVC和Web API。理想情况下,我想保护Web api的安全,但是我听说现在最好的方法是通过jwt。好-好酷
我可以继续配置jwt,然后将其用作我的身份验证/授权(https://blogs.msdn.microsoft.com/webdev/2017/04/06/jwt-validation-and-authorization-in-asp-net -core /),但是-我是否需要继续并启动一个新服务器以用作jwt的授权服务器?如果是这样,我就不会这样做(太贵了)。
如果我与jwt一起使用,我的.NET Core身份代码又如何?那那一定要消失吗?如果可以共存,我该如何用Identity来授权我的MVC页面以及用jwt来授权我的api端点?
我意识到这是一个开放式问题,但其核心是:
.NET核心标识和JWT可以共存吗?还是我必须选择一个?我有MVC和网络api,并希望同时保护两者。
c# ×6
asp.net ×3
asp.net-mvc ×2
sql ×2
arrays ×1
asp.net-core ×1
caching ×1
cfquery ×1
coldfusion ×1
cookies ×1
dapper ×1
django ×1
iis ×1
ios ×1
json ×1
jwt ×1
linq ×1
mysql ×1
outputcache ×1
powershell ×1
python ×1
xamarin.ios ×1