Posts

How to upload a file from Angular 6 to ASP.NET Core 2.1 Web API Application step by step

Image
This post talks about how to upload a file from Angular 6 to ASP.NET Core 2.1 Web API.  First thing first, let’s create an Angular 6 app with Visual Studio 2017. To do that, open Visual Studio 2017  community edition , hit Ctrl+Shift+N and select the ASP.NET Core Web Application (.NET Core) project type from the templates. When you click Ok, you will get the following prompt, Make sure to select “ASP.NET Core 2.1” from the version dropdown and choose Angular. The Visual Studio will create an ASP.NET Core 2.1 based project with Angular 6 configured. This should create an Angular 6 app. You should run the app to make sure that there are no errors. Create Upload API in ASP.NET Core To support uploading on the server, add a Web API controller named UploadController in the Controller folder. This controller has the API to upload the file and store it at a location. Add the controller with the following code. using Microsoft.AspNetCore.

Getting Started Build Angular 6 Web Application step by step

Image
In this article we will be building an Angular 6 application step by step from scratch with sample example. We will be generating our Angular 6 hello world application using angular CLI and then modify it to have a user management project where there will be a login screen for an admin and post login he can perform CRUD operations such as create, read, update and delete user with the sample REST API exposed using HttpClientModule. We will also be using RouterModule to have routing enabled. Also, at the end we will be integrating material designing with our Angular 6 app. Table of Contents     1. Angular 6 Highlights 2. Generating Angular 6 Project 3. Angular 6 Project Structure 4. Angular CLI Useful Commands 5. Angular 6 Routing 6. Spring Boot Implementation 7. Service in Angular 6 Application 8. Creating Components in Angular 6 9. Testing Angular 6 Application 10. Adding Material Design in Angular 6 App Angular 6 Release Highlights Angular v6 is the first release

Creation of the virtual directory failed issue whle opening the older version projects in VS2017[solved]

I attempted to load the new VS2015 project in VS2017, but it immediately failed to load.and i am getting below error popup Creation of the virtual directory http://localhost:32999/ failed with the error: Filename: redirection.config Error: Cannot read configuration file there are two solution for this issue 1) Renaming applicationhost.config :     Close VS2017     Go into folder %userprofile%\Documents\IISExpress\config     Rename applicationhost.config     Restart VS and load the solution/project     VS should have recreated applicationhost.config, and project should load 2) Copy config files to IISExpress directory copy all files from     C:\Program Files\IIS Express\config\templates\PersonalWebServer to     %userprofile%\Documents\IISExpress\config any of above solution will resolve your problem..

Security Exception in ASP.NET on shared hosting environment [solved]

When i was trying to host my newly developed website on shared server and i stuck with following exception Security Exception in ASP.NET [SecurityException: Request failed.] System.Security.CodeAccessSecurityEngine.ThrowSecurityException(RuntimeAssembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh, SecurityAction action, Object demand, IPermission permThatFailed) +165 System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh, SecurityAction action, Object demand, IPermission permThatFailed) +100 System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandleInternal rmh, Object assemblyOrString, SecurityAction action, Boolean throwException) +284 System.Security.CodeAccessSecurityEngine.CheckSetHelper(CompressedStack cs, PermissionSet grants, Per

System.Security.SecurityException: Request failed. issue on web server [resolved]

While hosting your website on shared hosting server you might get the System.Security.SecurityException: Request failed issue which will give you below stack trace on landing page of the website. Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. You can add below code to your Application web.config file to resolve it permanently   < system.web > < customErrors mode =" Off" / > < trust level =" Full" / > < /system.web >     This issue might occur in the case when serve

Cannot create type 'webservice' error solution

We create a web-service in development environment it working fine. But when we deploy the developed web service in production server many people get the Cannot create type 'some web-service  error. After finding the solution on the net i got one resolution which i am going to share now. To get ride of this error we need to re-install the .net framework 2.0 in IIS. This is essential to run web service on server. Following is the step you need to follow to register the .net framework in IIS. Open command prompt Then type >CD  C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\ aspnet_regiis.exe -i After above instruction the .net framework will be register in IIS. Now run the web service again. it should be run normally. Hurray you did it

Disable button after click in asp.net

To prevent double submit a form by user we need to restrict the user to click the button again. The idea is that we will use JavaScript to disable the button once user clicks first time. Add the following lines on .aspx page <asp:Button ID="btnProcess" runat="server" onclick="btnProcess_Click" Text="Process" /> Add the following line on .aspx.cs page (Page_Load). string strProcessScript = "this.value='Processing...';this.disabled=true;"; btnProcess.Attributes.Add("onclick", strProcessScript + ClientScript.GetPostBackEventReference(btnProcess, "").ToString()); This will disable Button, and then change the text of the button " Processing... ", and then continue on with the server side event btnProcess_OnClick event handler.

Prevent ASP.NET Forms Authentication from Timing Out on a Shared Hosting

I’m hosting a website on a shared hosting server. This site uses Forms Authentication to generate the session cookie that authenticates my users. Everything worked fine with the site, including authentication, until I tried to make it so my authentication cookies didn’t expire every 20 minutes, which is the default expiration setting for Forms Authentication I have set following settings to my web.config <authentication mode="Forms" > <forms loginUrl="~/Account/LogOn" timeout="2880" /> </authentication> but even though the user log outs from the system in 2 mins its irritating to user. To solve the issue we need to set machine key into the web.config file. To generate the machine key use following code snippet. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Security.Cryptography; namespace keygenerator { class Program { static void Main(string[] argv

File extension validation using javascript in MVC

This is article which demonstrate the validation of allowed file extension for upload of files in MVC using javascript. In this article i have used validation for valid image format like Jpeg, Jpg,Gif and png image format. If users ties to upload any other file apart from above mentioned file then the javascript function will shows proper message to user to select appropriate files. I have used html input file control for uploading of files in MVC application. following is the html code for it. <body> <div style="height:50px; padding-bottom:20px;"> @using (@Html.BeginForm("Create","FileUpload",FormMethod.Post,new{ enctype = "multipart/form-data"})) { <input type="file" id="file1" name="sdf" style=" margin-top:0px;" onchange="if( CheckExtention(this.value) ) {parent.ShowHideImage(true);this.form.submit();}" /> } </div> </body> and followi

Asp.Net MVC best practices part 1

If you decided to develop the application using Asp.Net MVC application and. I am going to demonstrate you to follow the best practices in MVC to develop the robust web application . If you want to log the exceptions occurs in controllers you need to write try catch blocks in each action method. This approach is also not recommended because you need to write try catch block in each action method. To get ride of this you can handle exceptions and log each exception by using centralized approach. These approaches are as follows Do not inherit the Controller base class directly to your Controllers Create new base custom controller class which inherits the base controller class Inherit created base custom controller class to your controllers Following is the sample code which demonstrate the above best practices public class BaseController : Controller { } In above code I have inherited the controller class to custom base controller class and below is the code to us