How to upload profile picture and update it in identity core 3

  • 问题

    I want to upload profile picture in identity user and update it in account management. if there is any post with good examples for core please give me links.



    I did it myself with FileForm Method. First You Have to Add string property in User Class(

            public string Avatar { get; set; }

    and then, update the Manage/Index files by following the documentation. Now, How to create the file upload system? I did like the code below. but if i need to change something for security, please don't forget to help.

                        if (Input.Avatar != null)
                        string existfile = Path.Combine(hostingEnvironment.WebRootPath, "uploads", user.Avatar);
                    var uploads = Path.Combine(hostingEnvironment.WebRootPath, "uploads", "avatar");
                    var filePath = Path.Combine(uploads, fileName);
                    this.Image.CopyTo(new FileStream(filePath, FileMode.Create));
                    user.Avatar = fileName; // Set the file name

    GetUniqueFileName Class after the PostAsync class:

            private string GetUniqueName(string fileName)
            fileName = Path.GetFileName(fileName);
            return Path.GetFileNameWithoutExtension(fileName)
                   + "_" + Guid.NewGuid().ToString().Substring(0, 4)
                   + Path.GetExtension(fileName);

    You also have to add the IWebHostEnvironment dependency injection and update the cshtml form with multipart/form-data enctype. Don't forget to follow the .net documentation rules also. Good Luck!

    share|improve this answer

    answered 11 hours ago

    Mizu HaqueMizu Haque 133 bronze badges

    add a comment |


  • I am new to android development, I am basically trying to create a very basic app which will enable the user to switch on their wifi.

    My XML file:

    <RelativeLayout xmlns:android="" xmlns:tools="" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="16dp" android:gravity="top" android:text="@string/welcome" android:textSize="25sp" /> <Button android:id="@+id/wifi_on" android:layout_width="150dp" android:layout_height="60dp" android:layout_below="@+id/textView1" android:layout_centerHorizontal="true" android:layout_marginTop="112dp" android:text="@string/wifi_button" />


    My Java file:

    package com.example.dosomething;

    import android.os.Bundle;``import;``import android.view.Menu;``import android.view.View;``import android.view.View.OnClickListener;``import android.widget.Button;

    public class MainActivity extends Activity implements OnClickListener {

    protected Button wifi_on; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(, menu); return true; } @Override public void onClick(View v) { // TODO Auto-generated method stub } public Button getWifiOn(){ return wifi_on; } public void setWifiOn(Button on){ wifi_on = on; }


    My question is how can I refer to the button inside the XML file onto the java file to further tell it that if the button is clicked on it should turn on the wifi. Thanks.

    There are several ways of doing this.

    What you can do is add this line to your <Button tag in xml


    then change the parameter of that function to

    public void getWifiOn(View v){ return wifi_on; }

    with this you don't need the onClick or any listeners

    2.You can do something similar if you want all Buttons to share the same function then give them all the function name like


    then in Java do something like

    public void someFunction(View v) { Button btn = (Button)v; switch (v.getId()) { case ( setWifiOn(btn); break; case ( // do some other things break; } } }

    3.Less attractive in many situations, IMHO

    public class MainActivity extends Activity implements OnClickListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button wifiBtn = (Button) findViewById(; wifiBtn.setOnClickListener(this); // your onClick below will be called then you will still have to check the id of the Button // multiple buttons can set the same listener and use a switch like above } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(, menu); return true; } @Override public void onClick(View v) { // TODO Auto-generated method stub }

    Note number 3 is the only one in which you need implements OnClickListener

    Button Docs

    I left out the other way because I think its the ugliest if you have more than one Button


    read more
  • Guys Please Help Me in The Morning it Was Working Fine Suddenly While i Was Running Test, it asked Me a Popup to Allow Access. Why i Dont Know. First i Cancelled That Pop up after again i Run The Test and Gave Access. From That Time Chrome Driver is Not Opening.


    Error Stack Trace :

    java.lang.IllegalStateException: The driver executable does not exist: E:\Workspace\xxxxxxxxx\‪‪C:\Users\xxxxx\Downloads\chromedriver.exe at at org.openqa.selenium.remote.service.DriverService.checkExecutable( at org.openqa.selenium.remote.service.DriverService.findExecutable( at$0( at$Builder.findDefaultExecutable( at org.openqa.selenium.remote.service.DriverService$ at at<init>( at Lead.FinalTest.beforeTest( at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.testng.internal.MethodInvocationHelper.invokeMethod( at org.testng.internal.Invoker.invokeConfigurationMethod( at org.testng.internal.Invoker.invokeConfigurations( at org.testng.internal.Invoker.invokeConfigurations( at org.testng.TestRunner.beforeRun( at at org.testng.SuiteRunner.runTest( at org.testng.SuiteRunner.runSequentially( at org.testng.SuiteRunner.privateRun( at at org.testng.SuiteRunnerWorker.runSuite( at at org.testng.TestNG.runSuitesSequentially( at org.testng.TestNG.runSuitesLocally( at at at org.testng.remote.RemoteTestNG.initAndRun( at org.testng.remote.RemoteTestNG.main(

    This error message...

    java.lang.IllegalStateException: The driver executable does not exist: E:\Workspace\xxxxxxxxx\‪‪C:\Users\xxxxx\Downloads\chromedriver.exe

    ...implies that the JVM was unable to find the ChromeDriver in the effective location as per the configuration mentioned within your code.

    As per your code trial, you have mentioned the location of the ChromeDriver as:


    But when your testcase gets executed the effective location is considered as:


    So, there are some configuration within your code block or IDE configuration or OS PATH variable which modifies the absolute path of the ChromeDriver binary. Addressing this issue will solve your problem.

    As error says, there is no executable driver exists in the path you have written.

    Make sure, that driver still exists in the path. Try to replace driver(if exists) in another folder and change path in the code Reinstall driver and set new path in the code

    PS: this is not a valid location:


    put chrome driver at
    and set same path in code System.setProperty("","C:\Users\xxxxx\Downloads\chromedriver.exe");

    This problem problem caused by special character in your path - f.e. some folder name contains 'ą' or 'ś' or space


    read more
  • Taking my initial steps towards Angular 2.0.

    First thing is to set up the right environment for the development.

    My index.html

    <html> <head> <title>Welcome to Angular 2.0</title> <!--css--> <link rel="stylesheet" type="text/css" href="css/bootstrap.css" /> </head> <body> <div class="container"> <h1> Hello Angular 2 </h1> <my-app> Loading app component....<my-app> </div> <!--js--> <!-- Polyfills for older browsers --> <script src=""></script> <script src=""></script> <script src=""></script> <script src=""> </script> <script> window.autoBootstrap = true; </script> <script src=""></script> <script> System.import('app').catch(function (e) { console.log(e); }); </script> <!--js--> </body> </html>

    I have copied the content from for the following files:-

    app.component.ts app.module.ts main.ts

    NPM is installed & running.


    But in order to get the node_modules folders with the required dependencies for the app to run. What commands do I need to run.

    What are the commands that I need to run to set up the Angular 2 environment?

    Please note I am new to NPM. Thanks.

    npm install in the root project (it will create your node_modules from the dependencies mentioned in package.json file, should have those files as a start)

    You have angular-cli wich is a good starter point. It will set you everything up according to best practices.

    Simple way to set up your first Angular 2 Application.

    Download the zip version here.firstAngular2App Extract it to your destination folder. Assume D: Open your command prompt(ensure that all required softwares are installed). Navigate it to the folder. Use the command cd D:\firstAngular2App Executre npm install Once it is done use npm start

    This way you have your first Angular2 appliction up and running.

    If you are already using Visual Studio Code as an IDE, you may want to explore how they recommend setting up Angular. I personally found their installation guide painless and feature-rich. I have never walked through an official Angular installation before due to being drenched in jQuery projects. This guide was simple enough to give me a good beginners understanding.


    read more








Powered by NodeBB | 备案号:宁ICP备15000671号