我读过很多关于相对/绝对路径的文章,但我仍然无法解决这个问题.
以下代码来自我的ASP.NET Master页面:
<li><a>Reports</a>
<ul>
<li>
<a href="/Reports/One.aspx">One</a>
</li>
<li>
<a href="~/Reports/Two.aspx">Two</a>
</li>
</ul>
</li>
Run Code Online (Sandbox Code Playgroud)
(注意,一个链接有一个~,一个没有.)
运行站点时,第一个链接指向http://server/Reports/One.aspx,第二个链接指向http://server/company/project/Reports/~/Reports/Two.aspx.
如何在不忽略IIS上设置的虚拟目录的情况下访问ASP.NET项目的根目录?
如何"处置"XDocument对象?我用它来解析XML字符串,然后将文件保存到文件系统.在同一方法中,我需要访问此文件并在其上运行命令行工具.
代码如下:
string filepath = "...";
string filename = "...";
XDocument xdoc = XDocument.Parse(xmlString);
xdoc.Save(filepath + filename);
Process p = Process.Start(new ProcessStartInfo("rst.exe", args)); // the args use the file saved above
Run Code Online (Sandbox Code Playgroud)
我在我调用命令行工具的行上放了一个断点,然后尝试自己手动打开文件,但是在我停止调试器之前它不会加载.
编辑:谢谢你的回答.我已经缩小的问题..保存文件后,并与断点"进程p = ...",我是能够打开文件,但使用我不能访问它http://qualifiedapppath/path/file.xml,和命令行我正在使用的工具只接受一个URL作为参数.停止调试器后,我可以通过http访问该文件.在方法运行时,哪个进程阻止访问它?
为什么slideDown()第一次不能工作?
$('#lnkInfo').click(function (e) {
e.preventDefault();
$(this).blur();
if ($(this).text() == 'More info') {
$('#spnMoreInfo').slideDown(200);
$(this).text('Less info');
}
else if ($(this).text() == 'Less info') {
$('#spnMoreInfo').slideUp(200);
$(this).text('More info');
}
});
Run Code Online (Sandbox Code Playgroud)
编辑:使用Firefox 22.0
使用Acunetix扫描我的Web应用程序后,结果显示9个"重定向页面中找到HTML表单"的实例.重现测试攻击的HTTP标头如下:
Request
GET /entities/add HTTP/1.1
Pragma: no-cache
Referer: https://test.mysite.com/entities/view
Acunetix-Aspect: enabled
Acunetix-Aspect-Password: 082119f75623eb7abd7bf357698ff66c
Acunetix-Aspect-Queries: filelist;aspectalerts
Cookie: __AntiXsrfToken=97c0a6bb164d4121b07327df405f9db4; mysitecookie=
Host: test.mysite.com
Connection: Keep-alive
Accept-Encoding: gzip,deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Acunetix-Product: WVS/8.0 (Acunetix Web Vulnerability Scanner - NORMAL)
Acunetix-Scanning-agreement: Third Party Scanning PROHIBITED
Acunetix-User-agreement: http://www.acunetix.com/wvs/disc.htm
Accept: */*
Response
HTTP/1.1 302 Found
Cache-Control: private
Content-Type: text/html; charset=utf-8
Location: /login
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
Set-Cookie: mysitecookie=; expires=Mon, 11-Oct-1999 22:00:00 GMT; path=/; HttpOnly
X-Powered-By: ASP.NET
Date: Tue, 24 Sep …Run Code Online (Sandbox Code Playgroud) 与这个困难的时间......
使用XLS(我在我的ASP.NET应用程序上使用NPOI)一切都工作100%:
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
private MemoryStream ms = new MemoryStream();
private IWorkbook workbook;
private ISheet worksheet;
private byte[] buffer;
using (FileStream file = new FileStream(@"C:\template.xls", FileMode.Open, FileAccess.Read))
{
workbook = new HSSFWorkbook(file);
}
worksheet = workbook.GetSheetAt(0);
worksheet.GetRow(11).GetCell(11).SetCellValue("hello"); // etc etc etc
workbook.Write(ms);
buffer = ms.ToArray();
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.Clear();
response.AddHeader("Content-Type", "application/vnd.ms-excel");
response.AddHeader("Content-Disposition", String.Format("attachment; filename=template.xls; size={0}", buffer.Length.ToString()));
response.BinaryWrite(buffer);
response.End();
Run Code Online (Sandbox Code Playgroud)
需求已更改,新的Excel模板使用XLSX中的功能,现在就是这样template.xlsx.我一直在使用NPOI 2.0,我发现它支持XLSX(使用XSSF而不是HSSF).我改变了这样的代码(只显示了这里的差异 - 其他一切都是一样的):
using NPOI.XSSF.UserModel;
using (FileStream file = new FileStream(@"C:\template.xlsx", FileMode.Open, FileAccess.Read))
{
workbook = …Run Code Online (Sandbox Code Playgroud) 为什么在Visual Studio 2012中创建ASP.NET 4.5 Web窗体项目web.config默认情况下具有以下内容:
...
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-Project.Web-20130625130806;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-Project.Web-20130625130806.mdf" />
</connectionStrings>
...
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
</providers>
</sessionState>
...
Run Code Online (Sandbox Code Playgroud)
(我的问题不是关于什么是LocalDb或为什么有一个示例连接字符串)
它在这里说这InProc意味着会话状态存储在内存中.为什么一旦你声明了,你需要指定一个连接字符串InProc?
我正在使用Bootstrap Multiselect显示年份列表,其中所选年份的最大数量可以是4.如果选择了4年,则禁用所有未选择的年份; 如果一年未被选中进行计数3,则再次启用所有年份.
(该插件项目的最新提交是添加启用/禁用功能,但我不认为这是针对个别选择元素的 - https://github.com/davidstutz/bootstrap-multiselect/issues/171)
我的HTML:
<select id="slYears" class="multiselect" multiple="multiple">
<option value="1" disabled="disabled">2009</option>
<option value="2" selected="selected">2010</option>
<option value="3" selected="selected">2011</option>
<option value="4" selected="selected">2012</option>
<option value="5" selected="selected">2013</option>
</select>
Run Code Online (Sandbox Code Playgroud)
我的JavaScript(第一次尝试):
$('#slYears').change(function () {
var arr = $(this).val().toString().split(',');
if (arr.length >= 4) {
$('#slYears option').each(function () {
if (!$(this).is(':selected')) {
$(this).prop('disabled', true);
}
});
}
else {
$('#slYears option').each(function () {
$(this).prop('disabled', false);
});
}
});
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用一些插件的方法和示例.我尝试使用'全选'示例启用所有,我尝试使用'onchange'事件,但没有一个工作.
这是jsfiddle:http://jsfiddle.net/389Af/1/(注意我在上面的JS之前粘贴了插件JS)
(与此问题类似)
我有一个名为'Questions'和'FinalFigures'的表格:
问题(QuestionID,Text,FinalFiguresColumnName)
FinalFigures(FinalFigureID,TotalDays,TotalCost等等)
'FinalFiguresColumnName'将具有"TotalDays","TotalCost"等值.是否有一种简单的方法可以循环一组问题,并将'Text'值保存到'FinalFigures'表中相应的列名?
IE浏览器.代替:
var item = new FinalFigure();
item.TotalDays = "x";
Run Code Online (Sandbox Code Playgroud)
我需要:
var item = new FinalFigure();
// access the column 'TotalDays' with its name as a string, not a property
Run Code Online (Sandbox Code Playgroud) 我有以下表与实体框架映射:
发票(InvoiceID,InvoiceNumber,IsPaid)
部件(PartID,PartNumber,OrganisationID,IsActive)
Invoices_Parts(InvoiceID,PartID,Quantity,IsClaimed)
我试图List从Invoices_Parts表中获得一个具有许多条件的InvoiceID .我有一个问题的条件是"凡任何 Part来自Invoices_Parts处于活动状态".
到目前为止的代码:
IQueryable<int> partIds = db.Parts.Where(x =>
x.OrganisationID == loggedInUser.OrganisationID).Select(y => y.PartID);
// && x.IsActive
List<string> invoiceIds = db.Invoices_Parts.Where(x =>
!x.IsClaimed && x.Invoice.IsPaid && partIds.Contains(x.PartID)
.DistinctBy(y => y.InvoiceID)
.Select(z => z.InvoiceID.ToString()).ToList();
Run Code Online (Sandbox Code Playgroud)
我已经注释掉了"&& x.IsActive",因为我希望InvoiceID列表至少有一部分必须符合IsActive条件 - 我不想过滤掉IsActive为false的所有部分.如何在LINQ中实现此功能而无需手动循环收集和添加/删除项目?
注意:如果有人想知道,我正在使用以下帮助方法DistinctBy:
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
HashSet<TKey> seenKeys = new HashSet<TKey>();
foreach (TSource element in source)
{
if (seenKeys.Add(keySelector(element)))
{
yield return …Run Code Online (Sandbox Code Playgroud) 我有这样一个实体:
public class Task
{
public string TaskID { get; set; }
public string Description { get; set; }
public string IsComplete { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我有一系列任务,如:
List<Task> tasks = new List<Task>();
tasks.Add(new Task() { TaskID = "1", Description = "A", IsComplete = "Yes" });
tasks.Add(new Task() { TaskID = "2", Description = "B", IsComplete = "No" });
Run Code Online (Sandbox Code Playgroud)
我试图string从这个集合中划分以下内容:
1#Yes,2#No
我设法得到了:
string delimitedString = String.Join(",", tasks.ToList().Select(l => l.TaskID));
Run Code Online (Sandbox Code Playgroud)
...如何进一步选择和分离其他字段?