asp.net-mvc-5

How to configure Autofac and SignalR in a MVC 5 application

蹲街弑〆低调 提交于 2019-12-01 21:28:36
I am trying to configure an MVC 5 application to use SignalR 2.2.x and inject a service into my NotificationsHub . We are using Autofac for MVC but I am not sure on how to correctly configure this. Autofac documentation exists for NuGet Autofac.Integration.SignalR (3.0.2) and Autofac.Integration.Mvc (3.3.4) . What I am doing so far is register the hubs via: ContainerBuilder builder = new ContainerBuilder(); // Register MVC controllers. builder.RegisterControllers(typeof(MvcApplication).Assembly); builder.RegisterType<ServiceForSignalRHub>().AsImplementedInterfaces(); builder.RegisterType<...>(

Attribute Routing with Multiple Leading Zero Decimals

只愿长相守 提交于 2019-12-01 21:16:50
Current ActionResult: [Route("EvaluatorSetup/{evalYear}/{department}")] public ActionResult RoutedEvaluatorSetup(int evalYear, string department) { return EvaluatorSetup((int?)evalYear, department); } I would like to use the url: /EvaluatorSetup/2014/001.3244 where the {department} is a ultimately a string, however, the routing is not picking up {department} as a string. A. I don't know what type MVC is expecting for "001.3244", or what it is picking it up as. B. I want to maintain it as a string with optional leading zeros, as in the example. What am I doing wrong? Update: What I mean is,

Why I can't use HttpContext or HttpCookie? (Asp.Net Core 1.0)

青春壹個敷衍的年華 提交于 2019-12-01 21:06:36
Why can't I use HttpContext or HttpCookie ? Is there a special using? My actual usings: using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; My namespace: namespace eCoffee.Main My class + methods: public class AppRunCookie { public static string CookieName { get; set; } public static string Key { get; set; } public AppRunCookie(string key) { CookieName = "MyCookie_" + key; } public static void SetCookie(string key, int cookieExpireDate = 30) { HttpCookie myCookie = new HttpCookie(CookieName); myCookie["Key"] = key; myCookie.Expires = DateTime.Now

HangFire recurring task data

瘦欲@ 提交于 2019-12-01 20:41:34
问题 I am coding a MVC 5 internet application and am using HangFire for recurring tasks. If I have a Monthly recurring task, how can I get the value of the next execution time? Here is my code for the recurring task: RecurringJob.AddOrUpdate("AccountMonthlyActionExtendPaymentSubscription", () => accountService.AccountMonthlyActionExtendPaymentSubscription(), Cron.Monthly); I can retrieve the job data as follows: using (var connection = JobStorage.Current.GetConnection()) { var recurringJob =

Created a new view in MVC 5, opening the new view results in HTTP 404

心不动则不痛 提交于 2019-12-01 20:22:59
问题 When I open the default MVC views(index and create) it work fine, I can add data and get data from the database. When I create a new view it don't work. It gets Http 404. This is even if I duplicate the create view, only with a different file name. Error-message: Server Error in '/' Application. 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

Conditional ModelState Merge

做~自己de王妃 提交于 2019-12-01 20:08:50
问题 I implemented the 2nd response to the "Preserve ModelState Errors Across RedirectToAction?" question which involves using two custom ActionFilterAttributes. I like the solution, it keeps the code clean by just adding an attribute to methods that need the functionality. The solution works well in most cases, but I've run across an issue with a repeating Partial View. Basically I have Partial View that uses it's own Model, separate from the Model that parent view uses. The simplified version of

Customised IdentityUserRole primary key

让人想犯罪 __ 提交于 2019-12-01 19:59:44
问题 I'm using ASP.NET Identity Provider and EF 6 Code First and I have created a custom IdentityUserRole table which has an extra column OrganisationId . The custom table is named UserRole. The table currently has the default primary key of UserId and RoleId . I would like to have the OrganisationId column included in the Primary Key of the IdentityUserRole table. I can see the UserRole table in my database, and it's the one that's being used for the userroles (there's no aspnet_userrole table

Conditional ModelState Merge

佐手、 提交于 2019-12-01 19:58:37
I implemented the 2nd response to the " Preserve ModelState Errors Across RedirectToAction? " question which involves using two custom ActionFilterAttributes. I like the solution, it keeps the code clean by just adding an attribute to methods that need the functionality. The solution works well in most cases, but I've run across an issue with a repeating Partial View. Basically I have Partial View that uses it's own Model, separate from the Model that parent view uses. The simplified version of my code from the main View: @for (int i = 0; i < Model.Addresses.Count; i++) { address = (Address

BundleTable.EnableOptimizations true breaks jquery-ui all.css

大城市里の小女人 提交于 2019-12-01 19:53:57
In an Asp.Net MVC 5 application, I am creating a style bundle in my egisterBundles method. I'm using jquery-ui . Instead of listing all of the jquery-ui css files individually I'm using all.css , which imports all the rest. The code looks like this: bundles.Add(new StyleBundle("~/Content/css").Include( "~/Content/a.css", "~/Content/b.css", "~/Content/themes/base/all.css")); And all.css contains two lines: @import "base.css"; @import "theme.css"; This works, but only when I set BundleTable.EnableOptimizations = false. When I set BundleTable.EnableOptimizations = true then none of the jquery css

API Application Insights good practice to use

最后都变了- 提交于 2019-12-01 19:46:11
I read this documentation: https://docs.microsoft.com/en-us/azure/application-insights/app-insights-api-custom-events-metrics There are many different API method to track exceptions, track trace etc.. I have a ASP.NET MVC 5 application. For example, I have the following controller method (called by ajax): [AjaxErrorHandling] [HttpPost] public async Task SyncDriverToVistracks(int DriverID) { if ([condition]) { // some actions here try { driver.VistrackId = await _vistracksService.AddNewDriverToVistrackAsync(domain); await db.SaveChangesAsync(); } catch (VistracksApiException api_ex) { //