我有一个使用窗体身份验证设置为45分钟超时的asp.net 4.0应用程序。我想在会话过期后将用户重定向到超时页面。谁能告诉我该怎么做?我正在运行.net 4.0。
web.config具有:
<authentication mode="Forms">
<forms name=".ASPXAUTH" loginUrl="~/Login.aspx"
defaultUrl="~/Default.aspx" protection="All" timeout="45"
requireSSL="false">
</forms>
</authentication>
Run Code Online (Sandbox Code Playgroud)
Global.asax.cs文件具有:
void Session_End(object sender, EventArgs e)
{
Response.Redirect("~/Timeout.aspx");
}
Run Code Online (Sandbox Code Playgroud) 我在这四个不同的命名空间下有一堆类:
包含“myEnum”定义的两个类都不直接位于命名空间“ab”下。我在“abcx”和“abcz”中定义了“myEnum”,但出现以下错误:
命名空间“ab”已包含 myEnum 的定义。
为什么是这样?我该如何解决?
编辑:
嗯,我修好了。显然,在命名空间中我不能有像“ab202.x”这样的数字。这就是它所抱怨的。有谁知道为什么?
我有一个上传KML文件的处理程序,并返回带有KML文件作为属性的JSON:
context.Response.Write("{\"name\":\"" + FileName +
"\",\"type\":\"" + FileType +
"\",\"size\":\"" + FileSize +
"\",\"region_id\":\"" + regionID +
"\",\"kml\":\"" + HttpUtility.HtmlEncode(xmlData) + "\"}");
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我正在尝试使用KML进行编码,HttpUtility.HtmlEncode但我的响应中出现错误:
未捕获的异常:无效的JSON
如何在C#中对XML/KML文件进行属性编码,以便稍后在JavaScript中对其进行解码?
编辑#1:根据Cheeso的评论
我在IIS 7.5 Windows 7上使用ASP.NET,.NET版本4.我的处理程序是一个ashx文件.如果我HttpUtility.HtmlEncode(xmlData)从响应中省略KML数据(),则响应正常.
编辑#2
我也尝试使用System.Web.Script.Serialization.JavaScriptSerializer主持人的评论.我这样使用它:
System.Web.Script.Serialization.JavaScriptSerializer serializer;
context.Response.Write("{\"name\":\"" + FileName +
"\",\"type\":\"" + FileType +
"\",\"size\":\"" + FileSize +
"\",\"region_id\":\"" + regionID +
"\",\"kml\":\"" + serializer.Serialize(xmlData) + "\"}");
Run Code Online (Sandbox Code Playgroud)
我仍然得到相同的"无效的JSON"错误.
此代码是否会造成任何内存泄漏?或者代码有什么问题吗?
HTML:
<div id='info'></div>
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
var count = 0;
function KeepAlive()
{
count++;
$('#info').html(count);
var t=setTimeout(KeepAlive,1000);
}
KeepAlive();
Run Code Online (Sandbox Code Playgroud)
在这里运行测试:http: //jsfiddle.net/RjGav/
我在div中有一个大图像,我想滚动.但是我没有div滚动,而是滚动文档.
如何让图像在DIV中滚动而不是父或文档?
我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Force Scroll</title>
<style type="text/css">
.scrollable
{
overflow: auto;
}
</style>
</head>
<body>
<div class="scrollable">
<img src="image.jpg" alt="test image" />
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 给出以下HTML:
<h2><span>1</span><span>2</span></h2>
<h2><span>1</span><span>2</span></h2>
<h2><span>1</span><span>2</span></h2>
<h2><span>1</span><span>2</span></h2>
Run Code Online (Sandbox Code Playgroud)
我想从所有h2元素中删除第一个span 元素.
我尝试了以下只删除第一个h2的第一个跨度:
$("h2 span:first").remove();
$("h2 span").first().remove();
Run Code Online (Sandbox Code Playgroud) 在我的WCF应用程序中,我有一个类似这样的Global.asax.cs来检索基本URL:
protected void Application_Start(object sender, EventArgs e)
{
string baseURL = System.Web.HttpContext.Current.Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
}
Run Code Online (Sandbox Code Playgroud)
在我的开发框(localhost)中它工作正常.但是,当我把它推到生产的System.Web.HttpContext.Current.Request回报null.
任何人都知道为什么会发生这种情况?
我正在构建我的svcutil命令行以从OSEO模式生成业务对象.
每当它告诉我"xxx"类型丢失时,我确定我需要包含在命令行中的xsd并添加它.到目前为止,我的命令行如下所示:
svcutil /language:C# /namespace:*,OGC.OSEO.DataContract /out:IOSEO.cs oseo/1.0/oseo.wsdl oseo/1.0/oseo.xsd ows/2.0/owsAll.xsd ows/2.0/ows19115subset.xsd ows/2.0/owsAdditionalParameters.xsd ows/2.0/owsCommon.xsd ows/2.0/owsContents.xsd ows/2.0/owsDataIdentification.xsd ows/2.0/owsExceptionReport.xsd ows/2.0/owsGetCapabilities.xsd ows/2.0/owsGetResourceByID.xsd ows/2.0/owsInputOutputData.xsd ows/2.0/owsManifest.xsd ows/2.0/owsOperationsMetadata.xsd ows/2.0/owsServiceIdentification.xsd ows/2.0/owsServiceProvider.xsd ows/2.0/owsDomainType.xsd http://www.w3.org/2006/03/addressing/ws-addr.xsd sweCommon/2.0/block_components.xsd sweCommon/2.0/advanced_encodings.xsd sweCommon/2.0/basic_types.xsd sweCommon/2.0/choice_components.xsd sweCommon/2.0/record_components.xsd sweCommon/2.0/simple_components.xsd sweCommon/2.0/simple_encodings.xsd sweCommon/2.0/swe.xsd xlink/1.0.0/xlinks.xsd swes/2.0/swes.xsd swes/2.0/swesCommon.xsd swes/2.0/swesContents.xsd swes/2.0/swesDeleteSensor.xsd swes/2.0/swesDescribeSensor.xsd swes/2.0/swesInsertSensor.xsd swes/2.0/swesNotification.xsd swes/2.0/swesUpdateSensorDescription.xsd gml/3.2.1/basicTypes.xsd gml/3.2.1/coordinateOperations.xsd gml/3.2.1/coordinateReferenceSystems.xsd gml/3.2.1/coordinateSystems.xsd gml/3.2.1/coverage.xsd gml/3.2.1/datums.xsd gml/3.2.1/defaultStyle.xsd gml/3.2.1/deprecatedTypes.xsd gml/3.2.1/dictionary.xsd gml/3.2.1/direction.xsd gml/3.2.1/dynamicFeature.xsd gml/3.2.1/feature.xsd gml/3.2.1/geometryAggregates.xsd gml/3.2.1/geometryBasic0d1d.xsd gml/3.2.1/geometryBasic2d.xsd gml/3.2.1/geometryComplexes.xsd gml/3.2.1/geometryPrimitives.xsd gml/3.2.1/gml.xsd gml/3.2.1/gmlBase.xsd gml/3.2.1/grids.xsd gml/3.2.1/measures.xsd gml/3.2.1/observation.xsd gml/3.2.1/referenceSystems.xsd gml/3.2.1/temporal.xsd gml/3.2.1/temporalReferenceSystems.xsd gml/3.2.1/temporalTopology.xsd gml/3.2.1/topology.xsd gml/3.2.1/units.xsd gml/3.2.1/valueObjects.xsd gmd/applicationSchema.xsd gmd/citation.xsd gmd/constraints.xsd gmd/content.xsd gmd/dataQuality.xsd gmd/distribution.xsd gmd/extent.xsd gmd/freeText.xsd …Run Code Online (Sandbox Code Playgroud) 我想创建一个扩展方法,允许我调用ToSerializableDictionary(p => p.ID)而不是.ToDictionary(p => p.ID)在下面的LINQ上下文中.虽然我不确定我应该做什么类的扩展方法来替换ToDictionary<T>.
response.attributes = (
from granuleGroup in groups
let granuleRow = granuleGroup.First().First()
select new USDAttributes()
{
id = (int)granuleRow["id"],
...
attributes =
(
...
).ToDictionary(p => p.ID) <--** LINE IN QUESTION **
}
).ToList();
Run Code Online (Sandbox Code Playgroud)
我从这里获取的SerializableDictionary类是这样的,我可以序列化我的webservice中的字典对象,以返回与JSON一起使用的哈希表.
最初我正在为IDictionary创建一个扩展方法,所以我可以这样做:...).ToDictionary(p => p.ID).ToSerializableDictionary();但这已经完全失败了,因为这是我第一次创建扩展方法而且我不知道我在做什么.
public static class CollectionExtensions
{
public static SerializableDictionary<string, object> ToSerializableDictionary(this IDictionary<string,object> sequence)
{
SerializableDictionary<string, object> sDic = new SerializableDictionary<string, object>();
foreach (var item in sequence) …Run Code Online (Sandbox Code Playgroud) 使用LINQ将数据记录加载到对象中时出现以下错误.这是工作之前,我添加了两个额外的字段dataLevelId和dataLevel.我必须做一些我不应该做的事情,因为现在它不起作用.谁能发现我做错了什么?
{System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)...
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
var groups = reader.Cast<IDataRecord>()
.GroupBy(dr => new { ID = (int)dr["productId"] })
.GroupBy(g => g.Key.ID);
products = (
from productGroup in groups
let productRow = productGroup.First().First()
select new Product()
{
ID = Convert.ToString((int)productRow["productId"]),
Name = !DBNull.Value.Equals(productRow["name"]) ? (string)productRow["name"] : "",
OutputFormats =
(
from formatRow in productGroup.First()
select …Run Code Online (Sandbox Code Playgroud) c# ×5
javascript ×3
.net ×2
asp.net ×2
xml ×2
css ×1
html ×1
jquery ×1
json ×1
linq ×1
namespaces ×1
settimeout ×1
svcutil.exe ×1
wcf ×1
xsd ×1