Aby dołączyć bazę bez pliku logu można skorzystać z polecenia:
sp_attach_single_file_db @dbname= 'databasename', @physname= 'sciezka_do_pliku_mdf'
Blog o tematyce związanej z platformą .NET i szeroko pojętym programowaniem. Znajdziesz tu informacje nt. platformy .NET, języka C#, wiadomości o wzorcach projektowych oraz tworzeniu poprawnej architektury oprogramowania.
sp_attach_single_file_db @dbname= 'databasename', @physname= 'sciezka_do_pliku_mdf'
public static class MvcContext { public const string ContextName = "DatabaseContext"; public static DatabaseContext Current { get { if (HttpContext.Current.Items[ContextName] == null) { HttpContext.Current.Items[ContextName] = new DatabaseContext(); } return (DatabaseContext)HttpContext.Current.Items[ContextName]; } } }
public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AuthConfig.RegisterAuth(); } protected void Application_EndRequest() { var entityContext = HttpContext.Current.Items[MvcContext.ContextName] as DatabaseContext; if (entityContext != null) { entityContext.Dispose(); } } protected void Application_BeginRequest() { } }
var key = "klucz"; var value = "value"; var memoryCache = MemoryCache.Default; var cachePolicy = new CacheItemPolicy(); cachePolicy.SlidingExpiration = TimeSpan.FromMinutes(1); memoryCache.Add(key, value, cachePolicy); var valueFromCache = memoryCache[key]; if (valueFromCache == null) { memoryCache[key] = value; }
cachePolicy.AbsoluteExpiration = DateTime.Now.AddMinutes(1);
<script src="@Url.Content("~/Scripts/Site.js")"></script>
<script src="~/Scripts/Site.js"></script>
using System.Web.Optimization; namespace MvcApplication3 { public class BundleConfig { // For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725 public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/Scripts/jquery-{version}.js")); bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include( "~/Scripts/jquery-ui-{version}.js")); bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( "~/Scripts/jquery.unobtrusive*", "~/Scripts/jquery.validate*")); // Use the development version of Modernizr to develop with and learn from. Then, when you're // ready for production, use the build tool at http://modernizr.com to pick only the tests you need. bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( "~/Scripts/modernizr-*")); bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css")); bundles.Add(new StyleBundle("~/Content/themes/base/css").Include( "~/Content/themes/base/jquery.ui.core.css", "~/Content/themes/base/jquery.ui.resizable.css", "~/Content/themes/base/jquery.ui.selectable.css", "~/Content/themes/base/jquery.ui.accordion.css", "~/Content/themes/base/jquery.ui.autocomplete.css", "~/Content/themes/base/jquery.ui.button.css", "~/Content/themes/base/jquery.ui.dialog.css", "~/Content/themes/base/jquery.ui.slider.css", "~/Content/themes/base/jquery.ui.tabs.css", "~/Content/themes/base/jquery.ui.datepicker.css", "~/Content/themes/base/jquery.ui.progressbar.css", "~/Content/themes/base/jquery.ui.theme.css")); } } }
public interface IDependencyResolver { /// <summary> /// Resolves singly registered services that support arbitrary object creation. /// </summary> /// /// <returns> /// The requested service or object. /// </returns> /// <param name="serviceType">The type of the requested service or object.</param> object GetService(Type serviceType); /// <summary> /// Resolves multiply registered services. /// </summary> /// /// <returns> /// The requested services. /// </returns> /// <param name="serviceType">The type of the requested services.</param> IEnumerable<object> GetServices(Type serviceType); }
PM> Install-Package unity.Mvc3
public static class Bootstrapper { public static void Initialise() { var container = BuildUnityContainer(); DependencyResolver.SetResolver(new UnityDependencyResolver(container)); } private static IUnityContainer BuildUnityContainer() { var container = new UnityContainer(); // register all your components with the container here // it is NOT necessary to register your controllers // e.g. container.RegisterType<ITestService, TestService>(); return container; } }
public class MvcApplication : HttpApplication { protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AuthConfig.RegisterAuth(); Bootstrapper.Initialise(); } }
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -px "iisConf
igurationKey" C:\folder\iisConfKey.xml -pri
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -px "iisWasKey" C:\folder\iisWasKey.xml -pri
C:\folder\
c:\windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_regiis.exe -pi "iisConfigurationKey" c:\folder\iisconfkey.xml -exp
c:\windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_regiis.exe -pi "iisWasKey" c:\folder\iisWasKey.xml -exp
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis -pa
"iisConfKey"
<configprotecteddata> <providers> <add keyContainerName=”MyWebServerRSA” description=”Uses RsaCryptoServiceProvider to encrypt and decrypt” name=”MyWebServerRSAProvider” type=”System.Configuration.RsaProtectedConfigurationProvider,System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” /> </providers> </configProtectedData>
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis -pef "connection Strings" "C:\inetpub\WebApplication1" -prov "MyWebServerRSAProvider"
<connectionStrings configProtectionProvider="MyWebServerRSAProvider"> <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#"> <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" /> <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"> <EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#"> <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" /> <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"> <KeyName>Rsa Key</KeyName> </KeyInfo> <CipherData> <CipherValue>f19a64s6YB208ibupTTE6+8zWI3y+trQTAajwtpaoArJ8kLic2k0ifmmSmok3NU2Aw7vBUcR2oayzUsoJSuYIDePVr/zvI9/oMVuRMBE+nvzi598BlpZ3lxsggKiwrCO1U/h/zcgNQFuosu7PnX4Rz+4cXZB60LngaZe+Gk+jy8=</CipherValue> </CipherData> </EncryptedKey> </KeyInfo> <CipherData> <CipherValue>6xZXUTJzr/ovYhI4qvw06hBA9qj59AKiOpEuwdx175R8HCiY/toW4G31GZwI237cmNTMPdlJac/VGki9C/UhU6Ehwb7VQoM8LjiqiJnWNkjyOUJYJOa+uZhpoVtEY06trjMqcFtLP/hdNiDtOwvOxusSFxGioP4Jwvfl22qTSBuc4j1QS1t8PSr/5tlZFJkSV6rxflMPJ+4Z4FYTHdfCyuk3vdnbO2RKjHyx3kNqjEz1eeKrKfz2jH9b6pbMKNss91+fE/ERjeGgdaP8wmewCw67zfjfx7B9fz/FZCw5MK+L2rUsnQMjqXCQEodVBbQtrDSGIlIAcQXGng8h2F9U09AzDSyZRrY+</CipherValue> </CipherData> </EncryptedData> </connectionStrings>