登录到MVC 5 ASP.NET模板从根文件夹移动时Web应用程序失败
我使用ASP.NET Web应用程序模板创建了一个带有“身份验证:个人用户帐户”的新“单页应用程序”.它将使用默认设置运行,没有任何问题.
如果我不将应用程序部署到Web服务器的根文件夹,则身份验证将失败.罪魁祸首在app.viewmodel.js文件中,可以找到以下代码: self.addViewModel = function (options) { var viewItem = new options.factory(self,dataModel),navigator; // Add view to AppViewModel.Views enum (for example,app.Views.Home). self.Views[options.name] = viewItem; // Add binding member to AppViewModel (for example,app.home); self[options.bindingMemberName] = ko.computed(function () { if (!dataModel.getAccessToken()) { // The following code looks for a fragment in the URL to get the access token which will be // used to call the protected Web API resource var fragment = common.getFragment(); if (fragment.access_token) { // returning with access token,restore old hash,or at least hide token window.location.hash = fragment.state || ''; dataModel.setAccessToken(fragment.access_token); } else { // no token - so bounce to Authorize endpoint in AccountController to sign in or register window.location = "/Account/Authorize?client_id=web&response_type=token&state=" + encodeURIComponent(window.location.hash); } } return self.Views[options.name]; }); window.location =“/ Account …”的行将浏览器重定向到根目录下的URL偏移量.不幸的是,只需将其硬编码到新文件夹(我想避免使用)并不能完全解决问题. 重定向似乎首先工作,但在AccountController.cs文件的幕后 我可能错过了显而易见的事实.我很感激任何指针. 这很容易复制.只需使用默认设置创建一个新的Web应用程序,然后进入项目属性并将“Project Url”更改为http:// localhost:49725 / foo,将应用程序移动到名为“foo”的新文件夹. 解决方法
我面临同样的问题,我所做的改变是:
>在app.viewmodel.js文件中,我添加了一个新参数(returnUrl): // no token - so bounce to Authorize endpoint in AccountController to sign in or register window.location = "/Account/Authorize?client_id=web&response_type=token&state=" + encodeURIComponent(window.location.hash) + "&returnUrl=" + encodeURIComponent(window.location); >在ApplicationOAuthProvider类的方法ValidateClientRedirectUri中,我读取了此参数并设置为返回URL: public override Task ValidateClientRedirectUri(OAuthValidateClientRedirectUriContext context) { if (context.ClientId == _publicClientId) { Uri expectedRootUri; if (!string.IsNullOrEmpty(context.Request.Query["returnUrl"])) { expectedRootUri = new Uri(context.Request.Query["returnUrl"]); } else { expectedRootUri = new Uri(context.Request.Uri,"/"); } if (expectedRootUri.AbsoluteUri == context.RedirectUri) { context.Validated(); } else if (context.ClientId == "web") { var expectedUri = new Uri(context.Request.Query["returnUrl"]); context.Validated(expectedUri.AbsoluteUri); } } return Task.FromResult<object>(null); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net – 如何访问listview中的按钮?特别是使用button_c
- ASP.NET:在URL中隐藏查询字符串
- asp.net mvc 依赖注入Ninject
- asp.net – 在负载均衡器上启用粘性会话
- asp.net-mvc – TempData在第二个请求后不会被破坏
- asp.net-mvc – dropzone.js和ASP.NET MVC文件发布是否为空
- 如何使用WebMatrix在ASP.NET网页中创建自定义错误页面?
- asp.net-mvc – 模型本身应该进行一些计算吗?
- asp.net – 错误HTTP 404.11通过查询字符串传递帐户激活令牌
- asp.net-mvc-3 – ASP.NET MVC3从https重定向到http
- 在dotnet发布后运行角度生产版本
- asp.net-core – 有没有办法将ASP.NET Core应用程
- asp.net-mvc – 从Asp.Net Mvc应用程序找不到Dat
- asp.net-web-api – MaxExpansionDepth,带有最新
- asp.net-mvc – 卸载OWIN和Identity包
- asp.net – Application_Start在工作站上工作正常
- ASP.NET MVC API 接口验证的示例代码
- asp.net – Solr Connection’已在容器中注册
- 为什么工作线程使我的ASP.NET生成器在睡眠期间遇
- asp.net-mvc – 在Asp.Net MVC中使用千位分隔符的