最近很多小伙伴都在问asp.net-mvc–scanMap的目的.CallingAssembly,scan.WithDefaultConventionsinStructureMap-MVC3这两个问题
最近很多小伙伴都在问asp.net-mvc – scanMap的目的.CallingAssembly,scan.WithDefaultConventions in StructureMap-MVC3这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展.NET Core MVC RequestLocalization忽略DefaultRequestCulture、.net core 简单集成JWT报No authenticationScheme was specified, and there was no DefaultChallengeScheme ...、.net – WinRT不支持Assembly.GetCallingAssembly,但适用于可移植类库?、asp.net – DefaultConnection和membership – localsqlserver和defaultconnection之间的连接是什么等相关知识,下面开始了哦!
本文目录一览:- asp.net-mvc – scanMap的目的.CallingAssembly,scan.WithDefaultConventions in StructureMap-MVC3
- .NET Core MVC RequestLocalization忽略DefaultRequestCulture
- .net core 简单集成JWT报No authenticationScheme was specified, and there was no DefaultChallengeScheme ...
- .net – WinRT不支持Assembly.GetCallingAssembly,但适用于可移植类库?
- asp.net – DefaultConnection和membership – localsqlserver和defaultconnection之间的连接是什么
asp.net-mvc – scanMap的目的.CallingAssembly,scan.WithDefaultConventions in StructureMap-MVC3
添加一个包含Initialize方法的IoC类(由App_Start文件夹中的某些代码调用),其中包含以下内容:
public static class IoC { public static IContainer Initialize() { ObjectFactory.Initialize(x => { x.Scan(scan => { scan.TheCallingAssembly(); scan.WithDefaultConventions(); }); // x.For<IExample>().Use<Example>(); }); return ObjectFactory.Container; } }
scan.CallingAssembly()和scan.WithDefaultConventions()代码的目的是什么?我在StructureMap documentation中看不到这些方法的好解释.
在非MVC项目中使用StructureMap时,我发现可以删除整个x.Scan部分而不会产生任何影响.
解决方法
WithDefaultConventions意味着:“如果在扫描时我找到了一个接口IExample,并且有一个类型示例实现了IExample,那么将Example注册为IExample的默认类型”.
在许多情况下,您将能够向容器询问您要查找的内容(IExample),并且它将返回实现,而无需任何进一步的配置.
.NET Core MVC RequestLocalization忽略DefaultRequestCulture
Startup.cs
public void ConfigureServices(IServiceCollection services) { services.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix,opts => { opts.ResourcesPath = "Resources"; }); } public void Configure(IApplicationBuilder app,IHostingEnvironment env,ILoggerFactory loggerFactory) { var english = "en-US"; var englishRequestCulture = new RequestCulture(culture: english,uiCulture: english); var supportedCultures = new List<CultureInfo> { new CultureInfo("en-US"),new CultureInfo("es-ES") }; var options = new RequestLocalizationoptions { DefaultRequestCulture = englishRequestCulture,SupportedCultures = supportedCultures,SupportedUICultures = supportedCultures }; app.UseRequestLocalization(options); app.UseMvc(); }
当将culture = en-US或culture = es-ES作为查询字符串参数传递时,这非常有效.我的期望是,当没有提供文化时,默认文化应该是en-US.但是,当我不提供culture参数时,我的视图默认为es-ES.我已确认所有其他本地化提供商也默认为en-US.
我还应该注意到,我尝试通过ConfigureServices()进行本地化,但是根本无法使其正常运行:
services.Configure<RequestLocalizationoptions>( options => { var supportedCultures = new List<CultureInfo> { new CultureInfo("en-US"),new CultureInfo("es-ES") }; options.DefaultRequestCulture = new RequestCulture(culture: "en-US",uiCulture: "en-US"); options.SupportedCultures = supportedCultures; options.SupportedUICultures = supportedCultures; });
解决方法
所以不,正如您和之前的回答所建议的那样,本地化中间件不会忽略DefaultRequestCulture.
.net core 简单集成JWT报No authenticationScheme was specified, and there was no DefaultChallengeScheme ...
#region JWT 认证
services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
//.AddCustomAuth(o => { })
.AddJwtBearer(options => {
options.TokenValidationParameters = new TokenValidationParameters {
ValidIssuer = Configuration["JwtSetting:Issuer"],
ValidAudience = Configuration["JwtSetting:Audience"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JwtSetting:SecurityKey"])),
// 默认允许 300s 的时间偏移量,设置为0
ClockSkew = TimeSpan.Zero
};
});
#endregion
#region MVC修改控制器描述
services.AddHttpContextAccessor();
services.Replace(ServiceDescriptor.Transient<IControllerActivator, ServiceBasedControllerActivator>());
services.AddMvc(config => {
config.RespectBrowserAcceptHeader = true;
//注入MVC拦截器
config.Filters.Add<ApiFilter>();
})
.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new ContractResolver())
.AddJsonOptions(options => options.SerializerSettings.Converters.Add(new ChinaDateTimeConverter()))
.AddFormatterMappings(options => options.SetMediaTypeMappingForFormat("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
.AddFormatterMappings(options => options.SetMediaTypeMappingForFormat("jpeg", "image/jpeg"))
.AddFormatterMappings(options => options.SetMediaTypeMappingForFormat("jpg", "image/jpeg"));
#endregion
在ConfigureServices中 注册JWT必须在注册MVC之前 否则就会报No authenticationScheme was specified, and there was no DefaultChallengeScheme found错误
app.UseAuthentication();
app.UseMvc();
在Configure中 添加JWT验证也必须在MVC之前,否则也会报错。
.net – WinRT不支持Assembly.GetCallingAssembly,但适用于可移植类库?
> Phone 7.0+
> .Net 1.0
> Portable Class Libraries
但是,不支持的位置直接位于Windows应用商店应用程序中.我可以创建一个可移植的类库,然后从Windows应用程序内部调用它,但我不能直接将它放在Windows应用商店应用程序/类库中.
是否有解决方法来获取由Assembly提供的元数据类型或其他方式?
typeof(MainPage).GetTypeInfo().Assembly
但那根本不一样.使用受限制的反射模型,也无法在.NET中获得运行时的堆栈跟踪.
至于可移植类库,我当然会说可以在可移植类库中支持Assembly.GetCurrentAssembly(),但不是在WinRT中 – 如果它不在那个平台中就有意义.但实际上,它似乎存在于包括WinRT在内的所有配置文件中,除了WinRT .NET4.5之外 – 似乎必须在某种程度上忽略这种不一致性.因此该方法存在于WinRT中(而且还没有进行重定向),但在编译时可用的元数据中不可见.
因此,您可以使用反射调用该方法:
var assembly = (Assembly) typeof(Assembly).GetTypeInfo() .GetDeclaredMethod("GetCallingAssembly") .Invoke(null,new object[0]);
我认为在Windows应用商店应用中这种方法的不可见性是“我们希望这会消失”.
(这个答案只涉及“我可以”而不是“我应该”).
asp.net – DefaultConnection和membership – localsqlserver和defaultconnection之间的连接是什么
在web.config我有:
<connectionStrings> <clear /> <!--- need this to prevent using LocalsqlServer from machine.config or somewhere becouse it is not present when when publish to hosting --> <add name="DefaultConnection" providerName="System.Data.sqlClient" connectionString="Data Source=.\sqlEXPRESS;Initial Catalog=aspnet-Goaly-20120615111028;Integrated Security=sspI" /> </connectionStrings>
和
<membership defaultProvider="DefaultMembershipProvider"> <providers> <!-- I think this line is telling asp.net that I want the membership working agains defaultconnection,and not LocalsqlServer connection????? --> <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider,System.Web.Providers,Version=1.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minrequiredPasswordLength="6" minrequiredNonalphanumericCharacters="0" passwordAttemptwindow="10" applicationName="/" /> </providers> </membership>
但后来却在抱怨:
The connection name 'LocalsqlServer' was not found in the applications configuration or the connection string is empty.
当我在设置选项卡中使用VS2012 RC的发布时,我得到一个ModelContext和一个DefaultConnection,那么这应该如何工作呢?
我想要的只是在与modelcontext创建的表相同的数据库中获取成员资格表.
这应该是如此,但我必须过分复杂一些.
谢谢你的帮助.
问候
larsi
解决方法
添加< / clear>在membership元素和rolemangaer元素(如果存在于web.config中)中的连接字符串之前的标记将解决该问题.
<membership defaultProvider="DefaultMembershipProvider"> <providers> <clear/> <!-- solves the issue --> <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider,PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minrequiredPasswordLength="6" minrequiredNonalphanumericCharacters="0" passwordAttemptwindow="10" applicationName="/" /> </providers> </membership>
您也可以使用sqlMetal.exe将成员资格表添加到现有数据库.
关于asp.net-mvc – scanMap的目的.CallingAssembly,scan.WithDefaultConventions in StructureMap-MVC3的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于.NET Core MVC RequestLocalization忽略DefaultRequestCulture、.net core 简单集成JWT报No authenticationScheme was specified, and there was no DefaultChallengeScheme ...、.net – WinRT不支持Assembly.GetCallingAssembly,但适用于可移植类库?、asp.net – DefaultConnection和membership – localsqlserver和defaultconnection之间的连接是什么等相关知识的信息别忘了在本站进行查找喔。
本文标签: