Tag: angularjs

通过Angular进行基本身份validation,为什么抛出错误401

我有一个Angular应用程序,我正在尝试使用基本身份validation对我的REST服务进行身份validation。 我正在添加授权标题以及在base64中编码的相应“Base {username:password}”,我正在调用我的rest api但是仍然会回到401.我显然在这里错过了一步…… 这是角度代码: angular .module(‘myApp.services’) .factory(‘AuthenticationService’, [‘$http’, ‘$q’, ‘$location’, ‘Base64’, ‘SessionService’, function ($http, $q, $location, encoder, session) { return { authenticate: function (user, password) { var deferred = $q.defer(); var url = “http://localhost:28924/api/login”; if (user && password) { var encoded = encoder.encode(user + ‘:’ + password); $http.defaults.headers.common.Authorization = ‘Basic ‘ + encoded; console.log(‘here’); […]

angularjs:如何从隐藏输入类型的asp .net页面获取值?

有人知道如何做这个简单的事情:从angularjs的隐藏输入字段中获取值? 在没有真正成功的情况下搜索了很多…服务器端的C#写了一个产品ID,我需要检索它以将它传递给我的angularjs json服务。 如果你能够回答,那么就要百万倍!

将Angularjs表达式/变量作为路径参数传递给asp.net mvc操作链接

我们如何将angularjs表达式/ varibale传递给asp.net mvc actionlink? 这是我的asp.net mvc actionlink代码 @Html.ActionLink(“{{row.x}}”, “Details”, “Info”, new { id = “{{row.x}}” }, null) 在第一个参数{{row.x}}工作正常,因为它显示值,但当作为路由参数传递时,它保留为{{row.x}}并且不会评估。如果我删除引号它不编译。

加载集线器时出错。 确保您的集线器引用正确,例如

有两个页面:Login.aspx和Profile.aspx,它们是使用HTML和AngularJS构建的。 login.aspx页面使用ng-view获取Login-view或Signup View的模板。 使用的代码是: 视图存储在Template文件夹中,其名称为:loginTemplate.html和signupTemplate.html。 用于处理login.aspx页面的模块是: var app_login = angular.module(‘JouralApp_login’, [‘ngRoute’,’ngAnimate’]); var app_profile = angular.module(‘GameApp’, []); app_login.config([‘$routeProvider’, ‘$locationProvider’, function ($routeProvider, $locationProvider) { $locationProvider.html5Mode(true); $routeProvider .when(‘/login’, { templateUrl: ‘Jscript_Angular/Templates/loginTemplate.html’, controller: ‘loginController’ }) .when(‘/signup’, { templateUrl: ‘Jscript_Angular/Templates/signupTemplate.html’ }).otherwise({ redirectTo:’/login’ }) }]); 现在创建了我的Profile.aspx,其HTML代码如下: {{chat}} 在尝试将SignalR集成到我的项目中之前,每件事情都运转良好。 我做了两节课: 第1类: [assembly: OwinStartup(typeof(Startup))] public class Startup { public void Configuration(IAppBuilder app) { […]

无法使用Ninject将依赖项注入到从Angular Service调用的ASP.NET Web API控制器中

我正在使用Ninject和ASP.NET MVC 4.我正在使用存储库并希望进行构造函数注入以将存储库传递给其中一个控制器。 这是我的上下文对象(EntityFramework),它实现了我的StatTracker接口: public class StatTrackerRepository : IStatTrackerRepository { private GolfStatTrackerEntities _ctx; public StatTrackerRepository(GolfStatTrackerEntities ctx) { _ctx = ctx; } public IQueryable GetFacilites() { return _ctx.Facilities; } } 这是我的Repository界面: public interface IStatTrackerRepository { IQueryable GetFacilites(); } 然后调用我的家庭控制器: public class HomeController : Controller { public IStatTrackerRepository _repo { get; set; } public HomeController(IStatTrackerRepository repo) { […]

在asp.net Web api和angular js中使用的身份validation方法

我正在使用Web api和angular js创建一个网站,我对在我的网站上使用的身份validation感到非常困惑。 我创建了一个login.js ,其中有我的Login方法,它将我的用户名/ Emailid和密码发布到我的Web Api,web api中的方法将validation该用户。 码: $scope.Login() { $.post(“api/Authentication/Login”,Username,Password) { } } Web api代码: [Route] Public Task Login([FromBody] username,password) { //method to authenticate user from database. //Now the tricky parts comes like after authenticating user should i //just store the user id in my session like this Session[“userid]=id or //Should i go […]

使用angular post将两个参数传递给WEB API调用

我的WEB API控制器中有以下post方法: public async Task SendPost(Application application) 我使用angular.js $http.post通过javascript调用它,并将应用程序参数作为JSON传递: $http.post(“/api/AController/SendPost”, JSON.stringify(application)). success(function (data, status, headers, config) { } 这很有效。 现在我想将第二个参数作为一个简单的字符串传递(我无法修改现有的应用程序JSON对象)。我尝试了几种不同的方式在网上建议,但它们似乎都没有工作。 我需要能够像这样做: 控制器: public async Task SendPost(RentalApplication application,string test) 使用Javascript: $http.post(“/api/TessIntegration/SendPost”, {application:JSON.stringify(application),test:”Some value”}). success(function (data, status, headers, config) { }

凭据标志为“true”,但是“Access-Control-Allow-Credentials”

我正在尝试从AngularJS页面连接到ASP.NET Web-API Web服务,我得到以下内容 凭据标志为“true”,但“Access-Control-Allow-Credentials”标头为“”。 允许凭据必须为“true”。 因此不允许来源’ http:// localhost:221 ‘访问。 var cors = new EnableCorsAttribute(“http://localhost:221”, “*”,”GET,PUT,POST,DELETE”); config.EnableCors(cors); 使用此AngularJS $http({ method: ‘GET’, url: ‘http://localhost:1980/api/investors/62632’, headers: { ‘Content-Type’: ‘application/x-www-form-urlencoded’ }, withCredentials: true // withCredentials: true, }).then(function onUserComplete(response) { // this callback will be called asynchronously // when the response is available }, function onError(response) { // called asynchronously […]

api控制器的文件下载问题

public class DefaultController : Controller { // GET: Default public ActionResult Index() { return Download(); } public FileResult Download() { string xmlString = “my test xml data”; string fileName = “test” + “.xml”; return File(Encoding.UTF8.GetBytes(xmlString), “application/xml”, fileName); } } 我在asp.net mvc应用程序中有上面的代码来下载文件。 它工作正常,因为我的控制器inheritance到Controller。 但是当我将此代码移动到Webapi控制器时,它会在返回File时抛出错误。 经过分析,我发现webapi中的控制器inheritance到ApiController(system.web.http.api控制器)。 我发现ApiController中没有File类。 有没有选项在webapi控制器中实现下载文件function? 我在webapi控制器中尝试了下面的替代代码,但是一旦我调用它就看不到下载文件。 public HttpResponseMessage DownloadConstructedXmlFile() { var result = new […]

在Asp.net Web API中处理CORS预检

我的架构中有三个应用程序。 它们位于同一台服务器上,但具有不同的端口号。 A – Token Application (port 4444) – Asp.net WebApi B – API Application (port 3333) – Asp.net WebApi C – UI Application (port 2222) – AngularJS App. 申请流程如下 1- UI项目从令牌应用程序获取令牌(它需要Windows awxrsdsaWeffs12davalidation。)例如: awxrsdsaWeffs12da 2- UI应用程序将此标记放入自定义标头,该标头名为“accessToken” 例如:accessToken: awxrsdsaWeffs12da 3- UI应用程序向API Application Ex发送请求: http:myaddress:3333/api/TheRestServiceHere UI应用程序获得401错误。 哪个发送OPTIONS方法。 (我想预检问题) 在我的web api项目中,我启用了如下所示的Cors。 public static void Register(HttpConfiguration config) { …. […]