假设您在创建新的MVC(5)项目时忘记勾选Web API复选框(将其添加到项目中),您需要做什么才能添加Web API并使其正常工作?
有一堆迁移问题,但似乎都没有将Web API添加到MVC 5项目的完整和最新步骤,而且似乎已经从一些旧的答案中改变了.
有没有办法将代码中的Dictionary转换为url参数字符串?
例如
// An example list of parameters
Dictionary<string, object> parameters ...;
foreach (Item in List)
{
parameters.Add(Item.Name, Item.Value);
}
string url = "http://www.somesite.com?" + parameters.XX.ToString();
Run Code Online (Sandbox Code Playgroud)
在MVC HtmlHelpers内部,您可以使用UrlHelper(或控制器中的Url)生成URL,但在Web窗体代码隐藏中,此HtmlHelper不可用.
string url = UrlHelper.GenerateUrl("Default", "Action", "Controller",
new RouteValueDictionary(parameters), htmlHelper.RouteCollection ,
htmlHelper.ViewContext.RequestContext, true);
Run Code Online (Sandbox Code Playgroud)
如果没有MVC助手,如何在C#Web窗体代码隐藏(在MVC/Web窗体应用程序中)中完成?
根据Castle Windsor教程和早期版本的MVC(pre-6)和WebAPI,我使用了Castle Windsor与安装人员和设施.
ASP.NET(5)Core已经包含了一些依赖注入支持,但我仍然没有弄清楚如何连接它,我发现的几个样本看起来与我之前使用它的方式有很大不同(使用安装/设施).大多数示例早于ASP.NET(5)核心最近发布,有些似乎已经过时的信息.
它似乎从之前版本的组合根设置中发生了极大的变化,Microsoft.Framework.DependencyInjection.ServiceProvider
当我将其设置为Castle Windsor DI后备时,甚至无法解析所有依赖项.我还在深入研究细节,但没有太多最新信息.
我找到了这样的适配器:Github Castle.Windsor DI容器.
Startup.cs
private static IWindsorContainer container;
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory)
{
container = new WindsorContainer();
app.UseServices(services =>
{
// ADDED app.ApplicationServices FOR FALLBACK DI
container.Populate(services, app.ApplicationServices);
container.BeginScope();
return container.Resolve<IServiceProvider>();
});
// ... default stuff
Run Code Online (Sandbox Code Playgroud)
WindsorRegistration.cs
我添加了几行来添加Castle Windsor ILazyComponentLoader
后备.
using Castle.MicroKernel.Lifestyle;
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.Resolvers.SpecializedResolvers;
using Castle.Windsor;
using Microsoft.Framework.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Reflection;
namespace Notes.Infrastructure
{
/// <summary> …
Run Code Online (Sandbox Code Playgroud) dependency-injection castle-windsor asp.net-core-mvc asp.net-core
假设你有一辆带有轮胎系列的汽车.
@Entity
public class Car {
private Long id;
@OneToMany(mappedBy = "car")
private Set<Tire> tires = new HashSet<>();
}
@Entity
public class Tire {
private Long id;
...
}
Run Code Online (Sandbox Code Playgroud)
现在,如果您想要添加新车并添加现有轮胎,您可以获取整个现有轮胎实体以填充Car's Set.
是否可以简单地使用一些轮胎ID并保存汽车而不首先将整个轮胎实体提取到内存中?有没有办法用Tire Id保存它,如果它只是一个单轮胎实例而不是一个Set?使用JPA和Criteria API,或者可能是JPQL.
我有一个Java Hibernate项目配置,它与SQL Server 2008 R2一起使用,现在有了新的OS 8.1(从7开始)和SQL Server 2012(express),我无法连接到SQL服务器.
因为它适用于2008 R2 ,所以/应该在语法上正确的相关配置:
datasource.properties
jdbc.driverClassName=net.sourceforge.jtds.jdbc.Driver
jdbc.url=jdbc:jtds:sqlserver://localhost:1433/dbname;instance=SQLEXPRESS
jdbc.username=auser
jdbc.password=xyz
Run Code Online (Sandbox Code Playgroud)
我试过org.hibernate.dialect.SQLServerDialect
在2008 R2工作的两种方言.
hibernate.hbm2ddl.auto=create-drop
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
#hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
hibernate.show_sql=true
Run Code Online (Sandbox Code Playgroud)
springConfiguration.xml
<bean id="dataSource" class="org.apache.tomcat.dbcp.dbcp2.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
Run Code Online (Sandbox Code Playgroud)
SQL Server 2012安装了混合模式身份验证,SQL Server Management Studio连接没有问题(有或没有实例名称).
我已经更新了SQL Server Network Configuration
for SQLEXPRESS
.
SQLEXPRESS的协议:
TCP/IP Enabled
以及TCP/IP Properties - TCP Port
到1433年的所有.
我试过禁用Windows防火墙只是为了测试它是否在路上,但它会导致相同的错误.
我最终添加了防火墙规则,并按照这个优秀的配置SQL Express 2012中的一些步骤来接受远程连接文章. …
我使用http基本身份验证和SSL创建了一个WCF服务.(IIS atm的临时证书)
这是相关配置.
<services>
<service name="MyNamespace.MyService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttps"
name="MyEndPoint" contract="MyNamespace.IMyService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<!-- These will be false when deployed -->
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<!-- This doesn't do anything in IIS -->
<behavior name="CustomUsernameValidatorBehavior">
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="MyNamespace.CustomUserNameValidator" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="basicHttps">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</basicHttpBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)
由于我在IIS中托管的事实,我无法使用我的customUsernameValidator,并且IIS Basic身份验证尝试针对Windows的用户名和密码.
我创建了一个新用户,在本地禁用了登录,并将其放入一个新组(没有权限).用户的唯一目的是确保允许他们访问服务,而不是其他任何目的.该服务将在线,而非内部,例如内联网等.
我的问题归结为此,由于我使用的是真正的Windows用户,是否存在安全风险/影响?如果是这样,可以做些什么来保护这个服务/ IIS?
如果要采取措施防止信息"网络钓鱼",他们是否可以尝试使用不同的用户名和密码来查找凭据?
顺便说一下,这是在IIS和SSL中使用Http基本身份验证的WCF的工作绑定(减去其他一些端点等).它要求IIS安装了基本身份验证,以及要对其进行身份验证的Windows用户.我不想对Windows用户进行身份验证.
在最新版本的Iesi.Collections中缺少Iesi.Collections.Generic.ISet.似乎有三种选择:
Iesi.Collections.Generic.ReadOnlySet似乎最接近ISet,文档说明:
... although it's advertised as immutable it really isn't.
Anyone with access to the wrapped set can still change the set.
Run Code Online (Sandbox Code Playgroud)
似乎ReadOnlySet是ISet的最佳替代品?目前,实现是通过公共方法向集合添加项目,因此它似乎是最合适的.替代方案(IList,bag?)似乎需要更多资源或不那么快/有效)?还有更好的选择吗?(该列表不应该有重复,可以手动验证)
我会做的事情如下:
public virtual ISet<MyClass> MyClass
{
get { return this.myClass }
}
public virtual void AddItem(MyClass item)
{
... // Null checks and initialize ISet if null
myClass.Add(item)
}
Run Code Online (Sandbox Code Playgroud)
基本上它归结为替代品,是否存在没有负面影响的替代品,如速度等?
我尝试生成WSDL,然后使用客户端手动在WSDL中找到每个XSD.该服务目前只在我的本地主机上,尚未发布.
客户端收到以下错误:
该文件已被理解,但无法处理.WSDL文档包含无法解析的链接.下载'http:// localhost:xxxx/MyService.svc?xsd = xsd0'时出错.无法连接到远程服务器无法建立连接,因为目标计算机主动拒绝它127.0.0.1:xxxx
如何生成和共享服务WSDL和XSD,以便他们可以开始编写客户端(无需访问服务atm?
编辑 WSDL/XSD中与这些问题相关的问题
WSDL
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://localhost:xxxx/MyService.svc?xsd=xsd0"
namespace="http://tempuri.org/"/>
<xsd:import schemaLocation="http://localhost:xxxx/MyService.svc?xsd=xsd1"
namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
<xsd:import schemaLocation="http://localhost:xxxx/MyService.svc?xsd=xsd2"
namespace="**MYNAMESPACE**"/>
</xsd:schema>
Run Code Online (Sandbox Code Playgroud)
XSD
<xs:import schemaLocation="http://localhost:xxxx/MyService.svc?xsd=xsd1"
namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
Run Code Online (Sandbox Code Playgroud)
编辑2:
感谢@The Indian Programmmer
我能够生成一个代理类来使用此命令进行编程:
"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\svcutil.exe" -noconfig -namespace:*,SERVICE.INTERFACE.NAMESPACE -serializer:datacontractserializer https://My-PC/SvrLocation/MyService.svc?wsdl
(托管在本地IIS中)
我正在转换一个项目使用卫星装配.我创建了一个新的类库(名为"Resources").所有默认资源都位于根级别*.resx
.然后每个文化都有一个文件夹.
"en /"with *.en.resx
en-GB/with *.en-GB.resx
我将.resx文件更改Access Modifier
为"公共"并更改了这些设置.
BuildAction: EmbeddedResource
CopyToOutputDirectory: CopyAlways
Run Code Online (Sandbox Code Playgroud)
我确保.resx
设计人员*.Designer.cs
使用"Resources"命名空间.
我将类库添加到ASP.NET MVC应用程序中,并global.asax.cs
根据需要设置文化.
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");
Run Code Online (Sandbox Code Playgroud)
我尝试将al.exe
和Resgen.exe
命令添加到Resources类库中的post-build事件.
"C:\ Program Files\Microsoft SDKs\Windows\v7.1\Bin\Resgen.exe"en-GB/MyResourceFile.en-GB.resx"C:\ Program Files\Microsoft SDKs\Windows\v7.1\Bin\al.exe"/ t:lib /embed:en-GB/MyResourceFile.en-GB.resources/culture:en-gb /out:Resources.resources.dll
查看MVC apps bin/
文件夹,每种语言都有3个文件夹:
MyResources.en-GB.Designer.cs,MyResources.en-GB.resx,Resources.resources.dll
根级别只有Resources.dll
,Resources.resources.dll
但默认语言工作正常.第二个*.resources.dll
是由于后期构建事件.
当我更改CurrentUICulture时,它不会更改UI语言.在将资源移出App_GlobalResources/
外部组件之前,它工作正常(Razor示例).
@Resources.MyResources.StringIdentifier
Run Code Online (Sandbox Code Playgroud)
.dlls
使用.NET Reflector 查看资源,这些是不同之处.
Satellite Resources: (Project: Resources)
Resources.en_GB.MyResources.en-GB.resources
App_GlobalResources: (Project MVCApp)
Namespace.MVCApp.App_GlobalResources.MyResources.en-GB.resources
Run Code Online (Sandbox Code Playgroud)
编辑:
在设置了CurrentCulture和UICulture之后global.asax.cs
,我测试 …
我没有在发行说明中看到任何内容,有人确定这个领域是否有任何改进?令人惊讶的是MS不支持.resx
开箱即用的SSRS报告文件.
我看到的唯一选择是创建一个单独的类库并使用它来检索资源字符串,如本文所示,它没有提到他们使用的SQL Server或VS版本.(与原始问题有关,它变成了只在2012年与2012年一起工作的报告)
我尝试了Visual Studio 2012 Pro试用版,但报告项目的迁移失败了.
ProjectName.rptproj:找不到此项目类型所基于的应用程序.
当项目在Visual Studio 2012中打开时,报告项目会(incompatible)
在下面的文字中说明
此项目与当前版本的Visual Studio不兼容.
c# ×5
asp.net-mvc ×3
asp.net ×2
hibernate ×2
java ×2
wcf ×2
.net ×1
asp.net-core ×1
dictionary ×1
iis ×1
jpa ×1
jtds ×1
localization ×1
nhibernate ×1
security ×1
sql-server ×1
ssrs-2012 ×1
webforms ×1
wsdl ×1
xsd ×1