我正在攻读MS证书(70-515).
我对在网上发现的内容和练习测试中的内容感到困惑.
关于SO的一些问题表明使用RedirectToAction正在向浏览器发送302,从而导致它在地址栏中更改它的url.
但这是一个练习测试的问题:
题:
MVC Home控制器目前只有默认的Index操作.相关代码显示在以下代码示例中.
public ActionResult Index()
{
ViewData["Message"] = "Hello!";
return View();
}
Run Code Online (Sandbox Code Playgroud)
您需要创建一个名为FindID的操作,该操作显示作为路径一部分输入的ID参数.如果路径不包含ID参数,则ASP.NET必须处理Index操作而不更改浏览器地址栏中的URL,并且不得抛出异常.您应该使用哪个代码段?
正确答案:
public ActionResult FindID(int? id)
{
if (!id.HasValue)
return RedirectToAction("Index");
ViewData["Message"] = "ID is " + id.ToString();
return View();
}
Run Code Online (Sandbox Code Playgroud)
说明:
您可以使用ActionResult的RedirectToAction形式使MVC处理动作中的不同操作.MVC放弃当前操作并处理请求,就像路由直接导致您重定向到的操作一样.实质上,这相当于在标准ASP.NET应用程序中调用Server.Transfer.
Redirect ActionResult向浏览器发送"HTTP Error 302 - Found"响应,这会导致浏览器加载指定的URL.这会更改地址栏中显示的地址.
所以:
- RedirectToAction是否保持浏览器中的URL不变?
- 重定向是否更改了浏览器中的URL?
- 练习测试的解释是否正确?据我所知,RedirectToAction不会做302.
我正在将几个Subversion存储库迁移到Git,但它们设置有点奇怪:标准的trunk/branches/tags结构存在于存储库的几个子目录中./ branches和/ tags都是空的,因此git-svn导入最终只有trunk目录.
svn/
proj1/
trunk/
src/
proj2/
trunk/
src/
Run Code Online (Sandbox Code Playgroud)
我想git filter-branch用来删除额外的trunk文件夹,但保持其余部分完整:
svn/
proj1/
src/
proj2/
src/
Run Code Online (Sandbox Code Playgroud)
git filter-branch --index-filter \
'git ls-files -s | sed "s-/trunk/-/-" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD
Run Code Online (Sandbox Code Playgroud)
在我看来,它sed正在做它的工作,因为这个输入:
100644 fa3dcf79717e9aca85ad745078a2fb2a2ce2b900 0 proj1/trunk/src/file1.txt
Run Code Online (Sandbox Code Playgroud)
生成此输出:
100644 fa3dcf79717e9aca85ad745078a2fb2a2ce2b900 0 proj1/src/file1.txt
Run Code Online (Sandbox Code Playgroud)
但是,当我运行整个命令时,我收到以下错误:
Rewrite e00c119cfb755f741dc0e17c36d36bc2ddd27562 (1/42)mv: cannot stat `/c/dev/R
epo/.git-rewrite/t/../index.new': No such file or directory
index filter failed: git ls-files -s | sed "s-/trunk/-/-" | …Run Code Online (Sandbox Code Playgroud) 我有一个Money带有隐式转换的简单类型decimal:
struct Money
{
decimal innerValue;
public static implicit operator Money(decimal value)
{
return new Money { innerValue = value };
}
public static explicit operator decimal(Money value)
{
return value.innerValue;
}
public static Money Parse(string s)
{
return decimal.Parse(s);
}
}
Run Code Online (Sandbox Code Playgroud)
我定义了一个Sum()重载来操作这些值:
static class MoneyExtensions
{
public static Money Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, Money> selector)
{
return source.Select(x => (decimal)selector(x)).Sum();
}
}
Run Code Online (Sandbox Code Playgroud)
我没想到的是这种扩展方法会干扰现有的Sum()扩展方法:
var source = new[] { "2" };
Money …Run Code Online (Sandbox Code Playgroud) NHibernate版本:2.1
我正在使用似乎是一个非常标准的HttpModule方法来实现ASP.NET + NHibernate应用程序中的每个请求会话.我正试图利用WebSessionContext,但它似乎没有正常工作.具体来说,对于应用程序上的第一个请求,一切都运行良好,但是其他请求会导致"会话关闭!" 任何时候使用会话的异常.重置应用程序池允许另一个请求成功,然后更多"会话关闭!".
有一些活动的部分,但我不知道如何管理上下文以缩小它...所以这就是一切!
在web.config中:
<property name="current_session_context_class">
NHibernate.Context.WebSessionContext, NHibernate
</property>
Run Code Online (Sandbox Code Playgroud)
(我也尝试将它设置为'web',结果相同.)
确认配置正确的模块:
public class NHibernateSessionModule : IHttpModule
{
public void Dispose() { }
public void Init(HttpApplication context)
{
Debug.WriteLine("NHibernateSessionModule.Init()");
context.BeginRequest += context_BeginRequest;
context.EndRequest += context_EndRequest;
}
void context_BeginRequest(object sender, EventArgs e)
{
Debug.WriteLine("NHibernateSessionModule.BeginRequest()");
var session = NHibernateHelper.OpenSession();
session.BeginTransaction();
CurrentSessionContext.Bind(session);
}
void context_EndRequest(object sender, EventArgs e)
{
Debug.WriteLine("NHibernateSessionModule.EndRequest()");
var session = NHibernateHelper.GetCurrentSession();
if (session != null)
{
try
{
if (session.Transaction != null && session.Transaction.IsActive)
session.Transaction.Commit(); …Run Code Online (Sandbox Code Playgroud) 我比较两个xml,我必须打印差异.如何使用LINQ实现此目的.我知道我可以使用Microsoft的XML diff补丁,但我更喜欢使用LINQ.如果您有任何其他想法,我会实现它
//第一个Xml
<Books>
<book>
<id="20504" image="C01" name="C# in Depth">
</book>
<book>
<id="20505" image="C02" name="ASP.NET">
</book>
<book>
<id="20506" image="C03" name="LINQ in Action ">
</book>
<book>
<id="20507" image="C04" name="Architecting Applications">
</book>
</Books>
Run Code Online (Sandbox Code Playgroud)
//第二个Xml
<Books>
<book>
<id="20504" image="C011" name="C# in Depth">
</book>
<book>
<id="20505" image="C02" name="ASP.NET 2.0">
</book>
<book>
<id="20506" image="C03" name="LINQ in Action ">
</book>
<book>
<id="20508" image="C04" name="Architecting Applications">
</book>
</Books>
Run Code Online (Sandbox Code Playgroud)
我想比较这两个xml和打印结果.
Issued Issue Type IssueInFirst IssueInSecond
1 image is different C01 C011
2 name is different ASP.NET ASP.NET 2.0 …Run Code Online (Sandbox Code Playgroud) System.Interactive.dll包含一个For()具有以下实现的方法:
IEnumerable<TResult> For<TSource, TResult>(
IEnumerable<TSource> source,
Func<TSource, IEnumerable<TResult>> resultSelector)
{
return source.Select<TSource, IEnumerable<TResult>>(resultSelector).Concat<TResult>();
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么或这相当于现有的Enumerable.SelectMany()减号this?
IEnumerable<TResult> SelectMany<TSource, TResult>(
this IEnumerable<TSource> source,
Func<TSource, IEnumerable<TResult>> selector)
Run Code Online (Sandbox Code Playgroud) 如何使用xml定义将查找字段添加到sharepoint中的内容类型?(我收到错误).
注意事项: - 将内容类型添加到文档库时,查找列表将存在. - 查找列表将始终具有相同的名称. - 查找列表在名称中有一个空格.
这是我添加到xml中的内容:
<Field ID="{GUID}"
Type="Lookup"
List="$Resources:core,lists_Folder;/List%20Name"
ShowField="Title"
Name="MyLookupFieldName"
DisplayName="MyLookupFieldName"
StaticName="MyLookupFieldName"
Hidden="FALSE"
Required="FALSE"
Sealed="TRUE"
>
Run Code Online (Sandbox Code Playgroud)
当我以编程方式将内容类型添加到文档库时,我得到一个异常(没有有用的信息),并将以下内容记录到sharepoint日志中:
2009年8月18日17:13:从SQL Server 39.50的w3wp.exe(0x08B8)0x11B0 Windows SharePoint Services数据库6f8g意外的意外查询执行失败,错误代码8114其他错误信息包含下面."将数据类型nvarchar转换为uniqueidentifier时出错." 查询文本(如果可用):"{?= call proc_GetListMetaDataAndEventReceivers(?,?,?,?,?,?)}"
有没有办法使用xbuild,通过命令行或在构建脚本中,将其他参数传递给编译器?具体来说,我想传入--mcs-debug 1以获取内部编译器错误的堆栈跟踪.
我能够通过更新来解决它%MONO%\bin\gmcs,但我希望有更好的方法.
我正在为我的FCKeditor使用ASP.NET二进制文件,并且需要在同一页面上插入两个编辑器.上传的图像/浏览需要转到两个不同的目录,如何从代码隐藏中执行此操作?
我知道上传文件的路径是在config.ascx-file中使用UserFilesPath设置设置的,但我找不到从我的aspx.cs文件中覆盖此值的方法.
此外,我发现(冲突的)文档说明Session["FCKeditor:UserFilesPath"]可以设置,但我不喜欢将usercontrol特定信息放在全局会话变量中.
我有一个搜索表单,允许用户以几种不同的方式搜索几个不同的字段.这是我的代码示例.
var claims = from c in db.Claims select c;
switch (ddlSearchField.Text)
{
case "StartsWith":
claims = claims.Where(c => c.companyFileID.StartsWith(txtSearchBox.Text));
break;
case "Equals":
claims = claims.Where(c => c.companyFileID == txtSearchBox.Text);
break;
case "Contains":
claims = claims.Where(c => c.companyFileID.Contains(txtSearchBox.Text));
break;
}
Run Code Online (Sandbox Code Playgroud)
我有大约十个不同的字段,用户可以搜索,所以我的外部开关语句非常大.必须有一种更优雅的方式来实现这一目标.
c# ×4
linq ×3
asp.net ×2
asp.net-mvc ×1
compare ×1
content-type ×1
delegates ×1
fckeditor ×1
git ×1
linq-to-sql ×1
linq-to-xml ×1
lookup-field ×1
nhibernate ×1
sharepoint ×1
upload ×1
xbuild ×1