Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 为什么MVC&;应用程序无法授权?_Angular_Authentication_Model View Controller - Fatal编程技术网

Angular 为什么MVC&;应用程序无法授权?

Angular 为什么MVC&;应用程序无法授权?,angular,authentication,model-view-controller,Angular,Authentication,Model View Controller,我有一个MVC应用程序,里面有一个角度应用程序。MVC运行服务器端代码并进行身份验证,保存cookie。但是当我切换到angular应用程序时,当我试图从服务器获取文件时,它会给我一条未授权的消息。我错过了什么。我假设cookie场景是自动的,我不会有这些问题。这可能是因为你启动Angular应用程序的方式 它可能在“localhost:4200上,而您的MVC应用程序可能运行在4200以外的主机上,比如说59970。这就是您的cookie不会被共享的原因 要使其工作,您需要设置一个从angul

我有一个MVC应用程序,里面有一个角度应用程序。MVC运行服务器端代码并进行身份验证,保存cookie。但是当我切换到angular应用程序时,当我试图从服务器获取文件时,它会给我一条未授权的消息。我错过了什么。我假设cookie场景是自动的,我不会有这些问题。

这可能是因为你启动Angular应用程序的方式

它可能在“localhost:4200上,而您的MVC应用程序可能运行在4200以外的主机上,比如说59970。这就是您的cookie不会被共享的原因

要使其工作,您需要设置一个从angular应用程序到MVC应用程序的代理

在angular应用程序的根目录下创建一个名为“proxy.conf.json”的json配置文件

{
  "/api/*": {
    "target": "http://localhost:59970",
    "secure": false,
    "logLevel": "debug",
    "changeOrigin": true
  }
}

现在,将package.json启动脚本更新为

“脚本”:{
“开始”:“ng serve--代理配置proxy.conf.json”
}