首先,这与SO上的另一个问题有关:
我通过以下SO文章和博客阅读并调试了我的问题:
MetadataException:无法加载指定的元数据资源
和
http://blogs.teamb.com/craigstuntz/2010/08/13/38628/
但是......除了这个"修复"之外我还有其他问题
我有一个WebAPI(2.1),我的WebAPI中的连接字符串是这样的:
<connectionStrings>
<add name="ProjectEntities" connectionString="
metadata=res://*/ProjectModel.csdl|
res://*/ProjectModel.ssdl|
res://*/ProjectModel.msl;
provider=System.Data.SqlClient;
provider connection string="
data source=192.168.0.1;
initial catalog=Project;
persist security info=True;
user id=***;
password=***;
multipleactiveresultsets=True;
App=EntityFramework""
providerName="System.Data.EntityClient" />
Run Code Online (Sandbox Code Playgroud)
当我在我的WebAPI(伪代码)中调用ToList()a DbSet时:
DbContext _DbContext = new ProjectEntities();
DbSet<TEntity> _dbSet = _DbContext.Set<TEntity>();
_dbSet.ToList();
Run Code Online (Sandbox Code Playgroud)
它很棒!
当我从WINDOWS SERVICE中调用相同内容时,出现以下错误:

连接字符串的app.config条目与web.config完全相同:
<connectionStrings>
<add name="ProjectEntities" connectionString="
metadata=res://*/ProjectModel.csdl|
res://*/ProjectModel.ssdl|
res://*/ProjectModel.msl;
provider=System.Data.SqlClient;
provider connection string="
data source=192.168.0.1;
initial catalog=Project;
persist security info=True;
user id=***;
password=***;
multipleactiveresultsets=True;
App=EntityFramework""
providerName="System.Data.EntityClient" /> …Run Code Online (Sandbox Code Playgroud) c# configuration entity-framework windows-services entity-framework-6
我正在Live Connect SDK(http://msdn.microsoft.com/en-us/live/default)上构建Metro C#SkyDrive API - 在Windows 8中,用户可以选择登录到Windows 8计算机使用LOCAL帐户或LIVE帐户.
使用Live Connect SDK时,如果我打电话
// assume wlscopes is properly set
LiveAuthClient liveAuthClient = new LiveAuthClient();
LiveLoginResult loginResult = await liveAuthClient.LoginAsync(wlscopes);
// do some stuff on skydrive
liveAuthClient.Logout(); // <-- issue only with live account, not local
Run Code Online (Sandbox Code Playgroud)
当使用LOCAL帐户时,它会让我退出(很棒)
当我在使用LIVE帐户时调用相同的代码时,我得到一个无法处理的异常 - 我甚至无法在此错误周围添加try {} catch {}.
例外:
Cannot sign out from the application since the user account is connected. (Exception from HRESULT: 0x8086000E)
Run Code Online (Sandbox Code Playgroud)
显然,由于在Live帐户下登录的用户无法注销,我的api需要检测当前用户是否正在使用真实帐户,因此我可以阻止调用logout()方法.
所以....我的问题是,我如何知道用户在Windows 8中使用哪种帐户类型?
我有一个视图模型女巫包含迭代项目.我通过EditorFor()方法将它们放在我的视图中.
视图:
@model Models.MyModel
@using (Html.BeginForm(@Model.Action, @Model.Controller))
{
<div class="section" id="Terms">
@Html.EditorFor(m => m.Terms)
</div>
<input type="submit" value="Save" />
}
Run Code Online (Sandbox Code Playgroud)
模型:
public class MyModel
{
public IEnumerable<Term> Terms { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
EditorTemplates\Term.cshtml:
@model Models.Term
@if (Model != null)
{
<fieldset>
<legend>Term</legend>
@Html.HiddenFor(model => model.TermID)
<div class="editor-label">
@Html.LabelFor(model => model.Identifier)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Identifier)
@Html.ValidationMessageFor(model => model.Identifier)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Description)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
</fieldset>
}
Run Code Online (Sandbox Code Playgroud)
我希望能够在视图中动态添加/删除列表中的项目,例如knockout.js上的这个示例,但是如何保留auto-id的MVC创建??:
我是MVC的新手,想知道在我的编辑器模板中填充下拉列表的最佳方法吗?
我正在构建一个具有大量下拉列表的应用程序,这些下拉列表的数据非常静态.目前我将它们全部放在db中的表中,然后将它们加载到会话中.
这是一个例子:
我的看法:
@{
var widgettypes = Business.MySession.Current.WidgetTypes.ToSelectList(d => d.TypeName,
d => d.WidgetTypeID.ToString(),
" - Select - ");
}
<div class="editor-label">
@Html.LabelFor(model => model.WidgetTypeID)
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.WidgetTypeID, @widgettypes)
@Html.ValidationMessageFor(model => model.WidgetTypeID)
</div>
Run Code Online (Sandbox Code Playgroud)
下拉助手:
public static List<SelectListItem> ToSelectList<T>(
this IEnumerable<T> enumerable,
Func<T, string> text,
Func<T, string> value,
string defaultOption)
{
var items = enumerable.Select(f => new SelectListItem()
{
Text = text(f),
Value = value(f)
}).ToList();
items.Insert(0, new SelectListItem()
{
Text = defaultOption,
Value = "-1"
});
return …Run Code Online (Sandbox Code Playgroud) 我使用uploadify上传文件,他们自动发布到处理程序.然后我修改了我在网站的公共类中设置为静态属性的处理程序中的会话.然后我尝试在aspx页面中访问同一个会话,值为null.我有一种感觉这是因为cookie,但需要有办法解决这个问题,而不会在网址中暴露sessionid.
ASHX:
public class Upload : IHttpHandler, IReadOnlySessionState, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
...
CMSSession.Current.UploadedFiles.Add(fileName);
}
}
Run Code Online (Sandbox Code Playgroud)
会话班:
public class CMSSession
{
public static CMSSession Current
{
get
{
CMSSession session = (CMSSession)HttpContext.Current.Session["__CMSSession__"];
if (session == null)
{
session = new CMSSession();
HttpContext.Current.Session["__CMSSession__"] = session;
}
return session;
}
}
public List<string> UploadedFiles { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
ASPX:
if (CMSSession.Current.UploadedFiles != null)
{
...
}
else
{
IT'S ALWAYS NULL
}
Run Code Online (Sandbox Code Playgroud)
Web.Config中:
<sessionState mode="InProc" cookieless="false" /> - …Run Code Online (Sandbox Code Playgroud) c# ×5
.net ×1
ashx ×1
asp.net ×1
asp.net-mvc ×1
file-upload ×1
knockout.js ×1
liveconnect ×1
razor ×1
webforms ×1
windows-8 ×1