asp.net-core-mvc

Asp.Net 5 MVC 6 detect mobile browser

我只是一个虾纸丫 提交于 2019-12-02 17:25:36
How is it possible in Asp.Net 5 MVC 6 to detect if the user is on a mobile device? In previous version of Asp MVC it could be done like this: Request.Browser.IsMobileDevice The problem is that the namespace System.Web is not used by Asp.Net 5 . The Request variable in the controller actions is now of type Microsoft.AspNet.Http.HttpRequest , the old version was of type System.Web.HttpRequestBase . Microsoft.AspNet.Http.HttpRequest does not contain the Browser property. I tried looking through other properties, but didn't find anything. EDIT: as requested some resources that prove that Asp.Net 5

Injecting multiple implementations with Dependency injection

跟風遠走 提交于 2019-12-02 17:18:35
I'm currently working on a ASP.NET Core Project and want to use the built-in Dependency Injection (DI) functionality. Well, I started with an interface: ICar { string Drive(); } and want to implement the ICar interface multiple times like public class BMW : ICar { public string Drive(){...}; } public class Jaguar : ICar { public string Drive(){...}; } and add the following in the Startup class public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc(); services.AddTransient<ICar, BMW>(); // or services.AddTransient<ICar, Jaguar>(); } Now I have to

How to design a Repository Pattern with Dependency Injection in ASP.NET Core MVC?

被刻印的时光 ゝ 提交于 2019-12-02 17:13:22
Being fairly new to ASP.NET Core 1.0 MVC, I have decided to use a Repository Pattern for an MVC Core app; I'm using a SQL DB for the Data Layer SampleDbContext , and I want to have a Repository class for some of my business Entities. So far I have done the following in the startup.cs , CustomerController.cs and CustomerRepository.cs files, where a sample Entity is "Customer". In the ConfigureServices method of the Startup Class: public void ConfigureServices(IServiceCollection services) { services.AddDbContext<SampleDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString(

How override ASP.NET Core Identity's password policy

两盒软妹~` 提交于 2019-12-02 17:00:26
By default, ASP.NET Core Identity's password policy require at least one special character, one uppercase letter, one number, ... How can I change this restrictions ? There is nothing about that in the documentation ( https://docs.asp.net/en/latest/security/authentication/identity.html ) I try to override the Identity's User Manager but I don't see which method manages the password policy. public class ApplicationUserManager : UserManager<ApplicationUser> { public ApplicationUserManager( DbContextOptions<SecurityDbContext> options, IServiceProvider services, IHttpContextAccessor

ASP.NET Core Application Lifecycle

折月煮酒 提交于 2019-12-02 16:46:34
Is there any current "ASP.NET Core" document(s) about the life cycle? I would like to be able to tie into the life cycle at the right points. Is it similar to the existing ASP.NET MVC 5 life cycle? http://www-asp.azureedge.net/v-2016-09-01-001/media/4773381/lifecycle-of-an-aspnet-mvc-5-application.pdf Here are few links I found related to ASP.NET Core lifecycle though this is not complete description and I'm searching for more. ASP.NET Core apps are console apps running on Kestrel so you can assume there are significant differences to what @mybirthname posted and it relates to ASP.NET 5 (and

How to compile .less files on save in Visual Studio 2015 (preview)

心已入冬 提交于 2019-12-02 16:34:00
Ok, so I've created a new ASP.Net 5 / MVC 6 project in Visual Studio 2015 Preview. In keeping with our current method of doing things, for styling I want to use .less files. Creating the files is straightforward, but Web Essentials no longer compiles them. So my question is this: what precisely do I need to do to get my .css files generated when I save the .less files? Based on my adventures getting Typescript to work nicely, I will have to use Grunt to accomplish this task, but I am brand-new to Grunt and so I'm not sure how one would do it? Please help! With VS 2015 Web Essential is split

ASP .NET 5 MVC 6 Identity 3 Roles Claims Groups [closed]

百般思念 提交于 2019-12-02 16:22:15
I'm currently looking for a solution to use an advanced Roles/Group Permission management in ASP .NET 5 MVC 6 with Identity 3. I started a new Preview Starter Web Project with a integrated easy login system. Now I need a complex "users permission management" with following functions: users can be in multiple groups/roles a group/role have many access objects (e.g. CanAccessUser, CanEditUser...) these access objects (maybe claims?) of each group/roles complement each other (optional for the ultimate solution): additionally => access objects(maybe claims) can be assigned independently by a group

I'm lost. What happened to ASP.NET MVC 5?

人盡茶涼 提交于 2019-12-02 14:15:00
I've been keeping my head down working on various projects and apparently Microsoft has been busy making some big changes and it's confusing the hell out of me. ASP.NET Core first came onto my radar when I installed Visual Studio 2017 last year and went to create a new project and suddenly had choices of .NET Framework, .NET Standard, and .NET Core. So I looked into them a little and saw that the latter two are, in some way, abbreviated versions of the full framework. I read this post by Scott Hanselman ASP.NET 5 is dead - Introducing ASP.NET Core 1.0 and .NET Core 1.0 I also found this, which

Submitting a razor form using JQuery AJAX in MVC6 using the built-in functionality

你离开我真会死。 提交于 2019-12-02 14:07:09
I would like to know if there is a specific way to submit a form using jQuery AJAX in MVC6, still using the Auto Binding features of ASP.NET MVC. I believe in other versions of MVC you could use jquery.unobtrusive-ajax and simply use @using (Ajax.BeginForm("SaveData", new AjaxOptions(){} Since there have been some changes with MVC6 I am wondering what the new recommended way to do this would be besides doing a normal AJAX post to the server when the form is submitted. This meaning I would manually get the values of each input field, turn them into JSON and send them over to the controller so

How to download PDF file on browser in Asp.net CORE MVC

巧了我就是萌 提交于 2019-12-02 13:18:05
I am using below code which used to download SSRS report in pdf format: string URL = "http://ssrs-test.com/ReportS/?/UAT_FOLDER"; URL = URL + "&SRNo=122&rs:Command=Render&rs:Format=pdf"; System.Net.HttpWebRequest Req = (System.Net.HttpWebRequest) System.Net.WebRequest.Create(URL); Req.Method = "GET"; string path = @ "E:\New folder\Test.pdf"; System.Net.WebResponse objResponse = Req.GetResponse(); System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create); System.IO.Stream stream = objResponse.GetResponseStream(); byte[] buf = new byte[1024]; int len = stream.Read(buf,