As the title says, I can't get Quartz.NET to work at all. I've got the latest versions of Quartz.NET (2.2.1), common.logging (2.1.2), common.logging.nlog (2.0.0), and NLog (2.1.0) from NuGet. Triggers aren't firing and there's absolutely nothing getting logged by Quartz. I'm guessing I screwed up the config somehow.
My App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
...
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" />
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog">
<arg key="configType" value="FILE" />
<arg key="configFile" value="~/NLog.config" />
</factoryAdapter>
</logging>
</common>
<quartz>
<add key="quartz.scheduler.instanceName" value="ServerScheduler" />
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
<add key="quartz.threadPool.threadCount" value="10" />
<add key="quartz.threadPool.threadPriority" value="2" />
<add key="quartz.jobStore.misfireThreshold" value="60000" />
<add key="quartz.jobStore.type" value="Quartz.Simpl.RAMJobStore, Quartz" />
</quartz>
...
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
...
<dependentAssembly>
<assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.2.0" newVersion="2.1.2.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
There's one job and one trigger associated with it:
{Trigger 'DEFAULT.DailyYahooUpdateTrigger': triggerClass: 'Quartz.Impl.Triggers.CronTriggerImpl calendar: '' misfireInstruction: 0 nextFireTime: 01/29/2014 18:38:00 +00:00}
[Quartz.Impl.Triggers.CronTriggerImpl]: {Trigger 'DEFAULT.DailyYahooUpdateTrigger': triggerClass: 'Quartz.Impl.Triggers.CronTriggerImpl calendar: '' misfireInstruction: 0 nextFireTime: 01/29/2014 18:38:00 +00:00}
CalendarName: null
Description: null
EndTimeUtc: null
FinalFireTimeUtc: null
HasMillisecondPrecision: false
JobDataMap: {Quartz.JobDataMap}
JobKey: {DEFAULT.DailyYahooUpdate}
Key: {DEFAULT.DailyYahooUpdateTrigger}
MisfireInstruction: 0
Priority: 5
StartTimeUtc: {29/1/2014 18:37:44 +00:00}
The scheduler is started, the job and trigger are added properly, and logging works otherwise. The nextFireTime comes and goes and nothing happens.
The trigger creation code:
ITrigger trigger = TriggerBuilder
.Create()
.WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(jobDetails.Time.Hours, jobDetails.Time.Minutes))
.StartNow()
.WithIdentity(jobDetails.Name + "Trigger")
.Build();
Based on your infos it should work; it should run once a day.
Make sure you have installed Common Logging NLog20]:
Install-Package Common.Logging.NLog20
And change this section:
<common>
<logging>
<factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20">
<arg key="configType" value="FILE" />
<arg key="configFile" value="~/NLog.config" />
</factoryAdapter>
</logging>
</common>
and this should be your runtime section:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
You can check the schedule of your trigger with this:
private static void GetNext10FireTimes(ITrigger trigger)
{
Console.WriteLine("List of next 10 schedules: ");
var dt = trigger.GetNextFireTimeUtc();
for (int i = 0; i < 10; i++)
{
if (dt == null)
break;
Console.WriteLine(dt.Value.ToLocalTime());
dt = trigger.GetFireTimeAfter(dt);
}
}
A full, working example can be found here (QuartzNetDailyAtHourAndMinute.zip).
I have reproduced your issue, and this has worked for me:
ITrigger trigger = TriggerBuilder
.Create()
.WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(jobDetails.Time.Hours, jobDetails.Time.Minutes))
.WithIdentity(jobDetails.Name + "Trigger")
.Build();
Remove the .StartNow() and the trigger should fire.
Hope it helps!
Related
I am absolutely at my wits end with this, having tried basically everything. I also do not see any existing stackoverflow threads about doing this.
I have an app.config file for my C# project, and it stores a list of servers which the user can create and add to.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="servers" type="System.Configuration.AppSettingsSection" />
</configSections>
<servers>
<add key="server" value="678,true,true"/>
</servers>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
<appSettings>
<add key="nightmode" value="Dark"/>
<add key="theme" value="Red"/>
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="ControlzEx" publicKeyToken="69f1c32f803d307e" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
((NameValueCollection)ConfigurationManager.GetSection("servers")).Add("server", $"{port}," + $"{ (dialogResult1 == MessageDialogResult.Affirmative) },{dialogResult2 == MessageDialogResult.Affirmative}");
When the user goes to add a new key the the "servers" section, it throws the below exception.
System.Configuration.ConfigurationErrorsException: 'The configuration is read only.'
I am bewildered why this is happening
you can try:
Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings.Add("test", "propertyValue");
config.Save(ConfigurationSaveMode.Modified, true);
System.Configuration.ConfigurationManager.RefreshSection("appSettings");
string test = ConfigurationManager.AppSettings["test"];
This get de appsettings section values.
Ps.: You need Install-Package System.Configuration.ConfigurationManager.
I ended up generating my own XML configuration, since that appears to be the best way to do things.
I'm trying to get ImageResizer working with the TinyCache plugin. (i'll be on ImageResizer Essential Edition).
I am under Windows 10 / IIS 10.0 with Integrated mode
I have a .net webform 4.7.2 website with the following NuGet packages installed:
ImageResizer (v4.2.5)
ImageResizer.Plugin.TinyCache (v4.2.5)
ImageResizer.WebConfig (v4.2.5)
My web.config is the following:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<!--<section name="resizer" type="ImageResizer.ResizerSection" requirePermission="false" />-->
<section name="resizer" type="ImageResizer.ResizerSection,ImageResizer" requirePermission="false" />
</configSections>
<!--check URL ~/resizer.debug.ashx-->
<resizer>
<!--Unless you (a) use Integrated mode, or (b) map all requests to ASP.NET,
you'll need to add .ashx to your image URLs: image.jpg.ashx?width=200&height=20
Using IIS7 Integrated mode or the Visual Studio web server? You can skip this step.
You also don't need to do this if you are using the .jpg.ashx syntax.-->
<pipeline fakeExtensions=".ashx" defaultCommands="autorotate.default=true" />
<plugins>
<add name="TinyCache" />
<!--<add name="VirtualFolder" virtualPath="~/" physicalPath="..\Assets" vpp="false "/>-->
<!--<add name="VirtualFolder" virtualPath="~/" physicalPath="../Assets" vpp="false "/>-->
</plugins>
</resizer>
<system.web>
<customErrors defaultRedirect="YourErrorPage.aspx"
mode="RemoteOnly">
</customErrors>
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2" />
<pages>
<namespaces>
<add namespace="System.Web.Optimization" />
</namespaces>
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
</controls>
</pages>
<httpModules>
<!-- This is for IIS7/8 Classic Mode and Cassini-->
<add name="ImageResizingModule" type="ImageResizer.InterceptModule" />
</httpModules>
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules>
<!--This is for IIS7+ Integrated mode-->
<add name="ImageResizingModule" type="ImageResizer.InterceptModule" />
</modules>
</system.webServer>
</configuration>
When I disable the TinyCache plugin (simply comment the <add name="TinyCache" /> line) it works when I try to call an image to resize (e.g. http:///Assets/TestImage.jpg?height=100 ; the image is resized ; here I have an TestImage.jpg picture in the Assets folder in the root directory of my website)
I however I get a warning on the diagnostic page http:///resizer.debug.ashx indicating I should enable cache:
(Warning): NoCache is only for development usage, and cannot scale to production use.
So I enable the TinyCache plugin in web.config.
Then I get a warning on the diagnostic page http:///resizer.debug.ashx which I am unable to get rid off : (Warning): To potentially see additional errors here, perform an image resize request.
If I then try to resize a picture (e.g. http:///Assets/TestImage.jpg?height=100 .... or event (e.g. http:///Assets/TestImage.jpg.ashx?height=100 which I should not need in my case with Win10 - IIS 10 Integrated mode) I get the following error :
Note : the english version of this error (I'm in French) would be
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Worth noted, the file /App_Data/tiny_cache.cache is never created ! (I have however granted all privileges on this folder to the user running the IIS Pool.... as well as all users on my DEV box !)
If you have any idea/solution, many thanks in advance !
I'm considering using https://imageprocessor.org/ instead of ImageResizer as didn't come with any pain :)
You need to install the protobuf-net nuget package. Because the dll is missing, a FileNotFound exception is thrown, which in turn is converted to a 404 error.
Alright so I made a custom role provider for my website and no matter what I do I can't get the code in the overridden functions to get hit.
This is the Custom Role Provider
namespace XXX.Security
{
using System;
using System.Linq;
using XXX.Areas.AccountManagement;
using System.Web.Security;
public class AppRoleProvider : RoleProvider
{
public override string ApplicationName
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public override void AddUsersToRoles(string[] usernames, string[] roleNames)
{
throw new NotImplementedException();
}
public override void CreateRole(string roleName)
{
throw new NotImplementedException();
}
public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
{
throw new NotImplementedException();
}
public override string[] FindUsersInRole(string roleName, string usernameToMatch)
{
throw new NotImplementedException();
}
public override string[] GetAllRoles()
{
AccountManagementDbContext accountManagement = new AccountManagementDbContext("App Role Provider - GetAllRoles()");
string[] roles = accountManagement.getRoles();
return roles;
}
public override string[] GetRolesForUser(string username)
{
AccountManagementDbContext accountManagement = new AccountManagementDbContext("App Role Provider - GetRolesForUser()");
string[] userRoles = accountManagement.getRolesForUser(username);
return userRoles;
}
public override string[] GetUsersInRole(string roleName)
{
throw new NotImplementedException();
}
public override bool IsUserInRole(string username, string roleName)
{
AccountManagementDbContext accountManagement = new AccountManagementDbContext("App Role Provider - GetAllRoles()");
string[] userRoles = accountManagement.getRolesForUser(username);
return userRoles.Contains(roleName);
}
public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
{
throw new NotImplementedException();
}
public override bool RoleExists(string roleName)
{
throw new NotImplementedException();
}
}
}
Here is my web.config file
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<connectionStrings>
<add name="xxx"
providerName="System.Data.SqlClient"
connectionString="Data Source=xxx;
Initial Catalog=xxx;
Integrated Security=false;
User ID=xxx;
Password=xxx;"/>
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="EnableSimpleMembership" value="false" />
</appSettings>
<system.web>
<authentication mode="Windows" />
<roleManager defaultProvider="AppRoleProvider" enabled="true">
<providers>
<clear/>
<add name="AppRoleProvider" type="xxx.Security.AppRoleProvider"/>
</providers>
</roleManager>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1" />
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
<remove name="TelemetryCorrelationHttpModule" />
<add name="TelemetryCorrelationHttpModule" type="Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule, Microsoft.AspNet.TelemetryCorrelation" preCondition="integratedMode,managedHandler" />
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
</providers>
</entityFramework>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0" />
<add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
</configuration>
This is a custom Authorization Attribute I am using
namespace XXX.Models
{
using System.Web;
using System.Web.Mvc;
public class AccessDeniedAuthorizationAttribute : AuthorizeAttribute
{
public override void OnAuthorization(AuthorizationContext filterContext)
{
base.OnAuthorization(filterContext);
var user = HttpContext.Current.User.Identity.Name;
if (filterContext.Result is HttpUnauthorizedResult)
{
filterContext.Result = new RedirectResult("/AccessDenied");
}
}
}
}
Finally this is my controller
namespace XXX.Areas.Admin.Controllers
{
using Models;
using System.Web.Mvc;
public class AdminController : Controller
{
[AccessDeniedAuthorization(Roles = "Administrator")]
public ActionResult AdminHome()
{
var user = HttpContext.User.Identity.Name;
return View();
}
}
}
So here are some things I've tried to get this to work...
Tried using the default Authorize attribute on my controller action.
Tried specifying the other attributes in my web.config for the provider like so...
<system.web>
<authentication mode="Windows" />
<roleManager defaultProvider="AppRoleProvider" enabled="true">
<providers>
<clear/>
<add name="AppRoleProvider" type="XXX.Security.AppRoleProvider, XXX" connectionStringName="XXX"/>
</providers>
</roleManager>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1" />
</system.web>
I've hit all my overridden functions in the Role provider from a controller to make sure they worked and they all worked normally and hit the breakpoints I had in it. When I put a break point in my custom Authorization attribute though it hits when the controller action in the Admin controller gets called. I even looked at the HttpContext.Current.User.ProviderName and it is the name of my custom Role Provider.
Another thing that is weird is that my User.Identity is never filled out when it should be populating with my windows login information, so I would imagine this has to be some sort of problem with the windows authentication not working.
I have the windows authentication turned on in my project properties too. I also left anonymous authentication enabled as I need to use both types of authentication.
Also going to throw this out there. My custom Role provider is in my web project, but the acccountmanagementdbcontext it references is in a separate project, though I can't see that causing any issues.
** Update **
I found something while googling about changing the applicatonhost.config file for IIS express.
<windowsAuthentication enabled="true">
<providers>
<add value="Negotiate" />
<add value="NTLM" />
</providers>
</windowsAuthentication>
I did this, but still doesn't work.
** Update 2 **
It seems that for some reason the user has to enter their windows credentials at least one time for the windows authentication to be able to authenticate them. I tried it with my windows credentials, while running locally, and after I entered my credentials the code in my custom role provider was then hit.
I was under the impression that if windows authentication was turned on and a request was sent to a controller/action that required authentication that it would just pull the windows user's credentials automatically and then pass them to the role provider.
My boss says that if you're on the same network as the IIS server that it will automatically get the windows user's credentials, but I have my doubts, as I tried hosting this on my pc in IIS with a dns address in my host file and it still didn't auto populate my windows credentials into the HttpContext.User.Identity.
You have to be using Internet Explorer for the Windows authentication to happen automatically on start of the site. The HttpContext.User.Identity.Name property will be populated with the current Windows username if you access the site with IE. I was using Firefox at the time. Which is also why I thought it was incorrect that that property was not populated when I hit that controller action. In any browser other than IE you have to turn on Windows authentication and then enter your Windows credentials in the popup login box when trying to access an area of you site that you have restricted. I had that login popup disabled, so in my site when I tried to access a controller action that I had set as restricted it never passed the windows validation, because the Identity.Name would not be populated without entering your windows credentials in that popup login.
I created an Azure web job project that uses Fluent NHibernate for its ORM. The program itself works fine and does what it's supposed to. However, after publishing the web job and running it live, every single SQL statement that NHibernate generates is output to the log, and I don't want this.
I thought that NHibernate by default does not output SQL statements, and I would have to enable it explicitly. However, it seems to be happening automatically, and I can't seem to turn it off. Is there some setting somewhere that I need to set to stop this logging?
This is my configuration, my app.config, and an example database query:
NHibernate configuration
public static ISessionFactory CreateSessionFactory()
{
string connString = ConnectionStringHelper.ConnectionString;
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(connString)
)
.Cache(c => c
.UseQueryCache())
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Functions>())
.BuildSessionFactory();
}
App config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="AzureWebJobsDashboard" connectionString="DefaultEndpointsProtocol=https;AccountName=***;AccountKey=***" />
<add name="AzureWebJobsStorage" connectionString="DefaultEndpointsProtocol=https;AccountName=***;AccountKey=***" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.WindowsAzure.Storage" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Sample DB Query
using (ISessionFactory sessionFactory = CreateSessionFactory())
{
using (var session = sessionFactory.OpenSession())
{
var accountCrit = session.CreateCriteria<AccountRec>();
accountCrit.Add(Expression.Eq("AccountId", batch.AccountId));
var accounts = accountCrit.List<AccountRec>();
}
}
The above statement generates this in the Azure logs:
[09/06/2017 03:57:30 > 442002: INFO] NHibernate: SELECT this_.AccountId as AccountId9418_0_, this_.RingCentralId as RingCent2_9418_0_, this_.RingCentralExtension as RingCent3_9418_0_ FROM T_ACCOUNT this_ WHERE this_.AccountId = #p0;#p0 = '253' [Type: Int]
But I don't want it to generate that in the logs.
I'm guessing that somehow, Azure is enabling log4net and NHibernate is then able to broadcast its logging.
Try adding these blocks to your config and see what effect it has:
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
<log4net debug="false">
<appender name="WindowsDebugOutput" type="log4net.Appender.DebugAppender, log4net">
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<logger name="NHibernate.SQL" additivity="false">
<level value="OFF" />
<appender-ref ref="WindowsDebugOutput" />
</logger>
</log4net>
You might need to tweak the appender but the key is the OFF value in the logger.level. You might be able to set this at a higher, global level too. However, my knowledge of how to configure log4net is lacking.
I'm trying to use a config file by directing there from App.config.
I have created a folder named Config inside my solution and created a new config file named Environment.config.
My App.Config looks as following:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /></startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<appSettings configSource="Config/Environment.config"/>
</configuration>
and the Environment.config looks as the following:
<appSettings>
<add key="URL" value="http://foo.aspx"/>
</appSettings>
I'm getting an error which says:
Result Message:
OneTimeSetUp: System.Configuration.ConfigurationErrorsException : Configuration system failed to initialize
----> System.Configuration.ConfigurationErrorsException : The configSource attribute must be a relative physical path, so the '/' character is not allowed. (D:\tfs\QA - Automation\Projects\ReportAppeal\ReportAppeal\bin\Debug\ReportAppeal.dll.config line 22)
I have tried to switch from "/" to "\" but got a different error.
Result Message:
System.Configuration.ConfigurationErrorsException : Unable to open configSource file 'Config\Environment.config'. (D:\tfs\QA - Automation\Projects\ReportAppeal\ReportAppeal\bin\Debug\ReportAppeal.dll.config line 22)
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
I'll probably need to change the way I'm directing the Environment.config file but I'm not sure how.
As the error says:
The configSource attribute must be a relative physical path
So you will need to change your key to a physical path, not a relative one:
<appSettings configSource="C:\Config\Environment.config"/>
Or just leave it under the root:
<appSettings configSource="Environment.config"/>